zova-jsx 1.1.25 → 1.1.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/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { celEnvBase, getProperty, evaluateExpressions, isEmptyObject, isNil, isP
3
3
  import { toUpperCaseFirstChar } from '@cabloy/word-utils';
4
4
  import { classes } from 'typestyle';
5
5
  import { h, createTextVNode } from 'vue';
6
- import { BeanSimple, objectAssignReactive, cast, beanFullNameFromOnionName } from 'zova-core';
6
+ import { BeanSimple, objectAssignReactive, cast } from 'zova-core';
7
7
 
8
8
  const renderFieldJsxPropsSystem = ['children', 'v-slot', 'v-slot-scope', 'v-if', 'v-for', 'v-each', 'key'];
9
9
 
@@ -20,10 +20,10 @@ function isLegacyComponent(Component) {
20
20
  return typeof Component === 'string' && !Component.includes(':') && Component.charAt(0) >= 'A' && Component.charAt(0) <= 'Y';
21
21
  }
22
22
  function isJsxComponent(Component) {
23
- return typeof Component === 'object' && Component.$$typeof === 'zova-jsx:component';
23
+ return typeof Component === 'object' && Component?.$$typeof === 'zova-jsx:component';
24
24
  }
25
25
  function isJsxEvent(Component) {
26
- return typeof Component === 'object' && Component.$$typeof === 'zova-jsx:event';
26
+ return typeof Component === 'object' && Component?.$$typeof === 'zova-jsx:event';
27
27
  }
28
28
  function invokeProp(prop) {
29
29
  if (typeof prop === 'function') return prop();
@@ -34,14 +34,12 @@ function normalizePropName(name) {
34
34
  }
35
35
 
36
36
  class ZovaJsx extends BeanSimple {
37
- constructor(components, actions, celEnv) {
37
+ constructor(components, celEnv) {
38
38
  super();
39
39
  this._components = void 0;
40
- this._actions = void 0;
41
40
  this._celEnv = void 0;
42
41
  this._transientObject = void 0;
43
42
  this._components = components;
44
- this._actions = actions;
45
43
  this._celEnv = this._prepareCelEnv(celEnv ?? celEnvBase);
46
44
  }
47
45
  _prepareCelEnv(celEnv) {
@@ -72,26 +70,23 @@ class ZovaJsx extends BeanSimple {
72
70
  get components() {
73
71
  return this._components;
74
72
  }
75
- get actions() {
76
- return this._actions;
77
- }
78
73
  get celEnv() {
79
74
  return this._celEnv;
80
75
  }
81
76
  evaluateExpression(expression, celScope) {
82
77
  return evaluateExpressions(expression, celScope, this.celEnv);
83
78
  }
84
- renderJsxOrCel(componentOptions, props, celScope, renderContext) {
79
+ renderJsxOrCel(componentJsx, props, celScope, renderContext) {
85
80
  // component
86
- if (isJsxComponent(componentOptions)) {
81
+ if (isJsxComponent(componentJsx)) {
87
82
  const transientObject = this.transientObject;
88
83
  return () => {
89
84
  return this.setTransientObject(transientObject, () => {
90
- return this.render(componentOptions, props, celScope, renderContext);
85
+ return this.render(componentJsx, props, celScope, renderContext);
91
86
  });
92
87
  };
93
88
  }
94
- if (isJsxEvent(componentOptions)) {
89
+ if (isJsxEvent(componentJsx)) {
95
90
  let transientObject = this.transientObject;
96
91
  return event => {
97
92
  transientObject = {
@@ -99,17 +94,17 @@ class ZovaJsx extends BeanSimple {
99
94
  eventObject: event
100
95
  };
101
96
  return this.setTransientObject(transientObject, () => {
102
- return this.renderEvent(event, componentOptions, celScope, renderContext);
97
+ return this.renderEvent(event, componentJsx, celScope, renderContext);
103
98
  });
104
99
  };
105
100
  }
106
101
  // normal
107
- return this.evaluateExpression(componentOptions, celScope);
102
+ return this.evaluateExpression(componentJsx, celScope);
108
103
  }
109
- renderEvent(event, componentOptions, celScope, renderContext) {
104
+ renderEvent(event, componentJsx, celScope, renderContext) {
110
105
  // props
111
106
  if (event && event instanceof Event) {
112
- const props = this.renderJsxProps(componentOptions.props, {}, celScope, renderContext);
107
+ const props = this.renderJsxProps(componentJsx.props, {}, celScope, renderContext);
113
108
  if (props.stop) event.stopPropagation();
114
109
  if (props.prevent) event.preventDefault();
115
110
  }
@@ -118,10 +113,10 @@ class ZovaJsx extends BeanSimple {
118
113
  celScope = objectAssignReactive({}, celScope, {
119
114
  res: eventRes
120
115
  });
121
- return this.renderEventDirect(componentOptions, celScope, renderContext, eventRes);
116
+ return this.renderEventDirect(componentJsx, celScope, renderContext, eventRes);
122
117
  }
123
- renderEventDirect(componentOptions, celScope, renderContext, eventRes, next) {
124
- const actions = this._collectEventActions(componentOptions, celScope, renderContext, eventRes);
118
+ renderEventDirect(componentJsx, celScope, renderContext, eventRes, next) {
119
+ const actions = this._collectEventActions(componentJsx, celScope, renderContext, eventRes);
125
120
  if (!actions || actions.length === 0) return next ? next(undefined) : undefined;
126
121
  const transientObject = this.transientObject;
127
122
  return compose(actions)(undefined, actionRes => {
@@ -131,8 +126,8 @@ class ZovaJsx extends BeanSimple {
131
126
  });
132
127
  });
133
128
  }
134
- _collectEventActions(componentOptions, celScope, renderContext, eventRes) {
135
- let actionChildren = componentOptions.props?.children;
129
+ _collectEventActions(componentJsx, celScope, renderContext, eventRes) {
130
+ let actionChildren = componentJsx.props?.children;
136
131
  if (!actionChildren) return;
137
132
  if (!Array.isArray(actionChildren)) actionChildren = [actionChildren];
138
133
  const actions = [];
@@ -169,14 +164,7 @@ class ZovaJsx extends BeanSimple {
169
164
  const vIf = this.evaluateExpression(actionChild.props?.['v-if'], celScope);
170
165
  if (vIf === false) return next(undefined);
171
166
  // action
172
- if (actionChild.type === 'actionVar') {
173
- const props = this.renderJsxProps(actionChild.props, {}, celScope, renderContext);
174
- celScope[cast(props).name] = cast(props).value;
175
- return next(undefined);
176
- } else if (actionChild.type === 'actionExpr') {
177
- const expression = this.evaluateExpression(cast(actionChild.props)?.expression, celScope);
178
- return next(expression);
179
- } else if (isJsxEvent(actionChild)) {
167
+ if (actionChild.type === 'ActionActions') {
180
168
  // nested action
181
169
  eventRes[index] = [];
182
170
  return this.renderEventDirect(actionChild, objectAssignReactive({}, celScope), renderContext, eventRes[index], next);
@@ -188,8 +176,7 @@ class ZovaJsx extends BeanSimple {
188
176
  }
189
177
  _renderEventActionNormal(actionChild, celScope, renderContext, next) {
190
178
  // action
191
- const actionName = this.normalizeAction(actionChild.type);
192
- const beanFullName = beanFullNameFromOnionName(actionName, 'action');
179
+ const beanFullName = actionChild.type;
193
180
  const beanInstance = this.sys.bean._getBeanSyncOnly(beanFullName);
194
181
  if (beanInstance) {
195
182
  // sync
@@ -206,7 +193,7 @@ class ZovaJsx extends BeanSimple {
206
193
  _renderEventActionNormal_inner(beanInstance, actionChild, celScope, renderContext, next) {
207
194
  const onionOptions = beanInstance.$onionOptions;
208
195
  // props
209
- let props = this.renderJsxProps(actionChild.props, {}, celScope, renderContext);
196
+ let props = this.renderJsxProps(cast(actionChild.props).options, {}, celScope, renderContext);
210
197
  if (!isEmptyObject(onionOptions)) {
211
198
  // not use deepExtend, maybe: Maximum call stack size exceeded
212
199
  props = Object.assign({}, onionOptions, props);
@@ -214,24 +201,25 @@ class ZovaJsx extends BeanSimple {
214
201
  if (!renderContext) throw new Error('should provide renderContext');
215
202
  return beanInstance.execute(props, renderContext, next);
216
203
  }
217
- render(componentOptions, props, celScope, renderContext) {
218
- if (!componentOptions) {
219
- throw new Error(`render component should not ${componentOptions}`);
204
+ render(componentJsx, propsInit, celScope, renderContext) {
205
+ if (!componentJsx) {
206
+ throw new Error(`render component should not ${componentJsx}`);
220
207
  }
221
- props = props ?? {};
222
- componentOptions = this.normalizeComponenOptions(componentOptions);
208
+ componentJsx = this.normalizeComponenJsx(componentJsx, propsInit);
209
+ const componentProps = componentJsx.props;
210
+ const props = {}; // new one
223
211
  // vIf
224
- const vIf = this.evaluateExpression(componentOptions.props?.['v-if'], celScope);
212
+ const vIf = this.evaluateExpression(componentProps?.['v-if'], celScope);
225
213
  if (vIf === false) return;
226
214
  // component
227
- const Component = this.normalizeComponent(componentOptions.type);
215
+ const Component = this.normalizeComponent(componentJsx.type);
228
216
  // vFor
229
- const vFor = this.evaluateExpression(componentOptions.props?.['v-for'], celScope);
230
- if (!vFor) return this._renderJsxSingle(Component, componentOptions, props, celScope, renderContext);
217
+ const vFor = this.evaluateExpression(componentProps?.['v-for'], celScope);
218
+ if (!vFor) return this._renderJsxSingle(Component, componentJsx, props, celScope, renderContext);
231
219
  const children = [];
232
220
  for (let index = 0; index < vFor.length; index++) {
233
221
  const each = vFor[index];
234
- const eachName = this.evaluateExpression(componentOptions.props?.['v-each'], celScope) ?? 'each';
222
+ const eachName = this.evaluateExpression(componentJsx.props?.['v-each'], celScope) ?? 'each';
235
223
  const celScopeEach = objectAssignReactive({}, celScope, {
236
224
  [eachName]: each,
237
225
  [`${eachName}Index`]: index
@@ -239,22 +227,29 @@ class ZovaJsx extends BeanSimple {
239
227
  const propsEach = {
240
228
  ...props
241
229
  };
242
- const child = this._renderJsxSingle(Component, componentOptions, propsEach, celScopeEach, renderContext);
230
+ const child = this._renderJsxSingle(Component, componentJsx, propsEach, celScopeEach, renderContext);
243
231
  if (child) {
244
232
  children.push(child);
245
233
  }
246
234
  }
247
235
  return children;
248
236
  }
249
- normalizeComponenOptions(componentOptions) {
250
- if (typeof componentOptions === 'object') return componentOptions;
237
+ normalizeComponenJsx(componentJsx, propsInit) {
238
+ if (typeof componentJsx === 'object') {
239
+ return Object.assign({}, componentJsx, {
240
+ key: cast(propsInit)?.key ?? componentJsx.key,
241
+ props: Object.assign({}, componentJsx.props, propsInit)
242
+ });
243
+ }
251
244
  return {
252
- type: componentOptions
245
+ type: componentJsx,
246
+ props: propsInit
253
247
  };
254
248
  }
255
249
  normalizeComponent(type) {
256
250
  if (typeof type === 'function') return type;
257
- if (typeof type === 'string') {
251
+ // if type is native element, for example: 'div/input'
252
+ if (typeof type === 'string' && !isNativeElement(type)) {
258
253
  type = this.components?.[type] ?? type;
259
254
  }
260
255
  if (typeof type === 'string' && ['script', 'style', 'link'].includes(type)) {
@@ -263,27 +258,24 @@ class ZovaJsx extends BeanSimple {
263
258
  // div/QInput/Zova Component
264
259
  return type;
265
260
  }
266
- normalizeAction(type) {
267
- return this.actions?.[type] ?? type;
268
- }
269
- _renderJsxSingle(Component, componentOptions, props, celScope, renderContext) {
261
+ _renderJsxSingle(Component, componentJsx, props, celScope, renderContext) {
270
262
  const _isZovaComponent = isZovaComponent(Component);
271
263
  // key
272
- if (!cast(props).key && componentOptions.key) {
273
- cast(props).key = this.evaluateExpression(componentOptions.key, celScope);
264
+ if (!isNil(componentJsx.key)) {
265
+ cast(props).key = this.evaluateExpression(componentJsx.key, celScope);
274
266
  }
275
267
  // props
276
- this.renderJsxProps(componentOptions.props, props, celScope, renderContext);
268
+ this.renderJsxProps(componentJsx.props, props, celScope, renderContext);
277
269
  // children
278
270
  let children;
279
- const propsChildren = componentOptions.props?.children;
271
+ const propsChildren = componentJsx.props?.children;
280
272
  if (!propsChildren) {
281
273
  children = undefined;
282
274
  } else {
283
275
  if (isNativeElement(Component)) {
284
- children = this.renderJsxChildrenDirect(componentOptions.props.children, celScope, renderContext);
276
+ children = this.renderJsxChildrenDirect(componentJsx.props.children, celScope, renderContext);
285
277
  } else {
286
- const childrenCollect = this._renderJsxChildrenCollect(componentOptions.props.children, celScope, renderContext);
278
+ const childrenCollect = this._renderJsxChildrenCollect(componentJsx.props.children, celScope, renderContext);
287
279
  if (_isZovaComponent) {
288
280
  for (const key in childrenCollect) {
289
281
  const slot = childrenCollect[key];
@@ -1,41 +1,34 @@
1
1
  import type { VNode } from 'vue';
2
2
  import { celEnvBase } from '@cabloy/utils';
3
3
  import { BeanSimple } from 'zova-core';
4
- import type { IFormProviderComponents, TypeRenderComponent, TypeRenderComponentJsx, TypeRenderComponentJsxProps } from '../types/rest.ts';
4
+ import type { TypeRenderComponent, TypeRenderComponentJsx, TypeRenderComponentJsxProps } from '../types/rest.ts';
5
5
  type CelEnv = typeof celEnvBase;
6
6
  export declare class ZovaJsx extends BeanSimple {
7
7
  private _components;
8
- private _actions;
9
8
  private _celEnv;
10
9
  private _transientObject;
11
- constructor(components?: IFormProviderComponents, actions?: Record<string, string>, celEnv?: CelEnv);
10
+ constructor(components?: {}, celEnv?: CelEnv);
12
11
  private _prepareCelEnv;
13
12
  setTransientObject<T>(transientObject: {} | undefined, fnMethod: () => T): T;
14
13
  get transientObject(): any;
15
14
  get event(): Event | undefined;
16
- get components(): IFormProviderComponents | undefined;
17
- get actions(): Record<string, string> | undefined;
15
+ get components(): {} | undefined;
18
16
  get celEnv(): CelEnv;
19
17
  evaluateExpression(expression: any, celScope?: {}): any;
20
- renderJsxOrCel(componentOptions: TypeRenderComponent | any, props: {} | undefined, celScope: {}, renderContext: {}): any;
21
- renderEvent(event: Event, componentOptions: TypeRenderComponentJsx, celScope: {}, renderContext: {}): any;
22
- renderEventDirect(componentOptions: TypeRenderComponentJsx, celScope: {}, renderContext: {}, eventRes: any[], next?: Function): any;
18
+ renderJsxOrCel(componentJsx: TypeRenderComponent | any, props: {} | undefined, celScope?: {}, renderContext?: {}): any;
19
+ renderEvent(event: Event, componentJsx: TypeRenderComponentJsx, celScope?: {}, renderContext?: {}): any;
20
+ renderEventDirect(componentJsx: TypeRenderComponentJsx, celScope: {}, renderContext: {} | undefined, eventRes: any[], next?: Function): any;
23
21
  private _collectEventActions;
24
22
  private _actionHandler;
25
23
  private _renderEventActionNormal;
26
24
  private _renderEventActionNormal_inner;
27
- render(componentOptions: TypeRenderComponent, props: {} | undefined, celScope: {}, renderContext: {}): VNode<import("vue").RendererNode, import("vue").RendererElement, {
28
- [key: string]: any;
29
- }> | VNode<import("vue").RendererNode, import("vue").RendererElement, {
30
- [key: string]: any;
31
- }>[] | undefined;
32
- normalizeComponenOptions(componentOptions: TypeRenderComponent): TypeRenderComponentJsx;
25
+ render(componentJsx: TypeRenderComponent, propsInit: {} | undefined, celScope?: {}, renderContext?: {}): VNode | VNode[] | undefined;
26
+ normalizeComponenJsx(componentJsx: TypeRenderComponent, propsInit?: {}): TypeRenderComponentJsx;
33
27
  normalizeComponent(type: TypeRenderComponent): TypeRenderComponent;
34
- normalizeAction(type: string): string;
35
28
  private _renderJsxSingle;
36
- renderJsxProps(jsxProps: TypeRenderComponentJsxProps | undefined, props: {}, celScope: {}, renderContext: {}): {};
29
+ renderJsxProps(jsxProps: TypeRenderComponentJsxProps | undefined, props: {}, celScope?: {}, renderContext?: {}): {};
37
30
  private _renderJsxChildrenCollect;
38
- renderJsxChildrenDirect(jsxChildren: TypeRenderComponentJsx | TypeRenderComponentJsx[], celScope: {}, renderContext: {}): VNode<import("vue").RendererNode, import("vue").RendererElement, {
31
+ renderJsxChildrenDirect(jsxChildren: TypeRenderComponentJsx | TypeRenderComponentJsx[], celScope?: {}, renderContext?: {}): VNode<import("vue").RendererNode, import("vue").RendererElement, {
39
32
  [key: string]: any;
40
33
  }>[];
41
34
  }
@@ -19,5 +19,3 @@ export interface TypeRenderComponentJsx {
19
19
  }
20
20
  export type TypeRenderComponentNormal = Constructable<ComponentPublicInstance> | string;
21
21
  export type TypeRenderComponent = TypeRenderComponentNormal | TypeRenderComponentJsx;
22
- export interface IFormProviderComponents {
23
- }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zova-jsx",
3
- "version": "1.1.25",
4
- "gitHead": "31f5f5712ea26eaebb2eae9990e6a089c1f087ca",
3
+ "version": "1.1.27",
4
+ "gitHead": "da650d644d8851a92a8da4babaebfef74c9e8a5d",
5
5
  "description": "Zova JSX",
6
6
  "keywords": [
7
7
  "ioc",
@@ -41,10 +41,10 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@cabloy/compose": "^2.1.4",
44
- "@cabloy/utils": "^2.1.9",
45
- "@cabloy/word-utils": "^2.1.8",
44
+ "@cabloy/utils": "^2.1.15",
45
+ "@cabloy/word-utils": "^2.1.9",
46
46
  "typestyle": "^2.4.0",
47
47
  "vue": "^3.5.32",
48
- "zova-core": "^5.1.23"
48
+ "zova-core": "^5.1.24"
49
49
  }
50
50
  }