zova-jsx 1.1.25 → 1.1.26

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
@@ -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();
@@ -81,17 +81,17 @@ class ZovaJsx extends BeanSimple {
81
81
  evaluateExpression(expression, celScope) {
82
82
  return evaluateExpressions(expression, celScope, this.celEnv);
83
83
  }
84
- renderJsxOrCel(componentOptions, props, celScope, renderContext) {
84
+ renderJsxOrCel(componentJsx, props, celScope, renderContext) {
85
85
  // component
86
- if (isJsxComponent(componentOptions)) {
86
+ if (isJsxComponent(componentJsx)) {
87
87
  const transientObject = this.transientObject;
88
88
  return () => {
89
89
  return this.setTransientObject(transientObject, () => {
90
- return this.render(componentOptions, props, celScope, renderContext);
90
+ return this.render(componentJsx, props, celScope, renderContext);
91
91
  });
92
92
  };
93
93
  }
94
- if (isJsxEvent(componentOptions)) {
94
+ if (isJsxEvent(componentJsx)) {
95
95
  let transientObject = this.transientObject;
96
96
  return event => {
97
97
  transientObject = {
@@ -99,17 +99,17 @@ class ZovaJsx extends BeanSimple {
99
99
  eventObject: event
100
100
  };
101
101
  return this.setTransientObject(transientObject, () => {
102
- return this.renderEvent(event, componentOptions, celScope, renderContext);
102
+ return this.renderEvent(event, componentJsx, celScope, renderContext);
103
103
  });
104
104
  };
105
105
  }
106
106
  // normal
107
- return this.evaluateExpression(componentOptions, celScope);
107
+ return this.evaluateExpression(componentJsx, celScope);
108
108
  }
109
- renderEvent(event, componentOptions, celScope, renderContext) {
109
+ renderEvent(event, componentJsx, celScope, renderContext) {
110
110
  // props
111
111
  if (event && event instanceof Event) {
112
- const props = this.renderJsxProps(componentOptions.props, {}, celScope, renderContext);
112
+ const props = this.renderJsxProps(componentJsx.props, {}, celScope, renderContext);
113
113
  if (props.stop) event.stopPropagation();
114
114
  if (props.prevent) event.preventDefault();
115
115
  }
@@ -118,10 +118,10 @@ class ZovaJsx extends BeanSimple {
118
118
  celScope = objectAssignReactive({}, celScope, {
119
119
  res: eventRes
120
120
  });
121
- return this.renderEventDirect(componentOptions, celScope, renderContext, eventRes);
121
+ return this.renderEventDirect(componentJsx, celScope, renderContext, eventRes);
122
122
  }
123
- renderEventDirect(componentOptions, celScope, renderContext, eventRes, next) {
124
- const actions = this._collectEventActions(componentOptions, celScope, renderContext, eventRes);
123
+ renderEventDirect(componentJsx, celScope, renderContext, eventRes, next) {
124
+ const actions = this._collectEventActions(componentJsx, celScope, renderContext, eventRes);
125
125
  if (!actions || actions.length === 0) return next ? next(undefined) : undefined;
126
126
  const transientObject = this.transientObject;
127
127
  return compose(actions)(undefined, actionRes => {
@@ -131,8 +131,8 @@ class ZovaJsx extends BeanSimple {
131
131
  });
132
132
  });
133
133
  }
134
- _collectEventActions(componentOptions, celScope, renderContext, eventRes) {
135
- let actionChildren = componentOptions.props?.children;
134
+ _collectEventActions(componentJsx, celScope, renderContext, eventRes) {
135
+ let actionChildren = componentJsx.props?.children;
136
136
  if (!actionChildren) return;
137
137
  if (!Array.isArray(actionChildren)) actionChildren = [actionChildren];
138
138
  const actions = [];
@@ -214,24 +214,25 @@ class ZovaJsx extends BeanSimple {
214
214
  if (!renderContext) throw new Error('should provide renderContext');
215
215
  return beanInstance.execute(props, renderContext, next);
216
216
  }
217
- render(componentOptions, props, celScope, renderContext) {
218
- if (!componentOptions) {
219
- throw new Error(`render component should not ${componentOptions}`);
217
+ render(componentJsx, propsInit, celScope, renderContext) {
218
+ if (!componentJsx) {
219
+ throw new Error(`render component should not ${componentJsx}`);
220
220
  }
221
- props = props ?? {};
222
- componentOptions = this.normalizeComponenOptions(componentOptions);
221
+ componentJsx = this.normalizeComponenJsx(componentJsx, propsInit);
222
+ const componentProps = componentJsx.props;
223
+ const props = {}; // new one
223
224
  // vIf
224
- const vIf = this.evaluateExpression(componentOptions.props?.['v-if'], celScope);
225
+ const vIf = this.evaluateExpression(componentProps?.['v-if'], celScope);
225
226
  if (vIf === false) return;
226
227
  // component
227
- const Component = this.normalizeComponent(componentOptions.type);
228
+ const Component = this.normalizeComponent(componentJsx.type);
228
229
  // vFor
229
- const vFor = this.evaluateExpression(componentOptions.props?.['v-for'], celScope);
230
- if (!vFor) return this._renderJsxSingle(Component, componentOptions, props, celScope, renderContext);
230
+ const vFor = this.evaluateExpression(componentProps?.['v-for'], celScope);
231
+ if (!vFor) return this._renderJsxSingle(Component, componentJsx, props, celScope, renderContext);
231
232
  const children = [];
232
233
  for (let index = 0; index < vFor.length; index++) {
233
234
  const each = vFor[index];
234
- const eachName = this.evaluateExpression(componentOptions.props?.['v-each'], celScope) ?? 'each';
235
+ const eachName = this.evaluateExpression(componentJsx.props?.['v-each'], celScope) ?? 'each';
235
236
  const celScopeEach = objectAssignReactive({}, celScope, {
236
237
  [eachName]: each,
237
238
  [`${eachName}Index`]: index
@@ -239,22 +240,29 @@ class ZovaJsx extends BeanSimple {
239
240
  const propsEach = {
240
241
  ...props
241
242
  };
242
- const child = this._renderJsxSingle(Component, componentOptions, propsEach, celScopeEach, renderContext);
243
+ const child = this._renderJsxSingle(Component, componentJsx, propsEach, celScopeEach, renderContext);
243
244
  if (child) {
244
245
  children.push(child);
245
246
  }
246
247
  }
247
248
  return children;
248
249
  }
249
- normalizeComponenOptions(componentOptions) {
250
- if (typeof componentOptions === 'object') return componentOptions;
250
+ normalizeComponenJsx(componentJsx, propsInit) {
251
+ if (typeof componentJsx === 'object') {
252
+ return Object.assign({}, componentJsx, {
253
+ key: cast(propsInit)?.key ?? componentJsx.key,
254
+ props: Object.assign({}, componentJsx.props, propsInit)
255
+ });
256
+ }
251
257
  return {
252
- type: componentOptions
258
+ type: componentJsx,
259
+ props: propsInit
253
260
  };
254
261
  }
255
262
  normalizeComponent(type) {
256
263
  if (typeof type === 'function') return type;
257
- if (typeof type === 'string') {
264
+ // if type is native element, for example: 'div/input'
265
+ if (typeof type === 'string' && !isNativeElement(type)) {
258
266
  type = this.components?.[type] ?? type;
259
267
  }
260
268
  if (typeof type === 'string' && ['script', 'style', 'link'].includes(type)) {
@@ -266,24 +274,24 @@ class ZovaJsx extends BeanSimple {
266
274
  normalizeAction(type) {
267
275
  return this.actions?.[type] ?? type;
268
276
  }
269
- _renderJsxSingle(Component, componentOptions, props, celScope, renderContext) {
277
+ _renderJsxSingle(Component, componentJsx, props, celScope, renderContext) {
270
278
  const _isZovaComponent = isZovaComponent(Component);
271
279
  // key
272
- if (!cast(props).key && componentOptions.key) {
273
- cast(props).key = this.evaluateExpression(componentOptions.key, celScope);
280
+ if (!isNil(componentJsx.key)) {
281
+ cast(props).key = this.evaluateExpression(componentJsx.key, celScope);
274
282
  }
275
283
  // props
276
- this.renderJsxProps(componentOptions.props, props, celScope, renderContext);
284
+ this.renderJsxProps(componentJsx.props, props, celScope, renderContext);
277
285
  // children
278
286
  let children;
279
- const propsChildren = componentOptions.props?.children;
287
+ const propsChildren = componentJsx.props?.children;
280
288
  if (!propsChildren) {
281
289
  children = undefined;
282
290
  } else {
283
291
  if (isNativeElement(Component)) {
284
- children = this.renderJsxChildrenDirect(componentOptions.props.children, celScope, renderContext);
292
+ children = this.renderJsxChildrenDirect(componentJsx.props.children, celScope, renderContext);
285
293
  } else {
286
- const childrenCollect = this._renderJsxChildrenCollect(componentOptions.props.children, celScope, renderContext);
294
+ const childrenCollect = this._renderJsxChildrenCollect(componentJsx.props.children, celScope, renderContext);
287
295
  if (_isZovaComponent) {
288
296
  for (const key in childrenCollect) {
289
297
  const slot = childrenCollect[key];
@@ -1,41 +1,37 @@
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
8
  private _actions;
9
9
  private _celEnv;
10
10
  private _transientObject;
11
- constructor(components?: IFormProviderComponents, actions?: Record<string, string>, celEnv?: CelEnv);
11
+ constructor(components?: {}, actions?: Record<string, string>, celEnv?: CelEnv);
12
12
  private _prepareCelEnv;
13
13
  setTransientObject<T>(transientObject: {} | undefined, fnMethod: () => T): T;
14
14
  get transientObject(): any;
15
15
  get event(): Event | undefined;
16
- get components(): IFormProviderComponents | undefined;
16
+ get components(): {} | undefined;
17
17
  get actions(): Record<string, string> | undefined;
18
18
  get celEnv(): CelEnv;
19
19
  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;
20
+ renderJsxOrCel(componentJsx: TypeRenderComponent | any, props: {} | undefined, celScope?: {}, renderContext?: {}): any;
21
+ renderEvent(event: Event, componentJsx: TypeRenderComponentJsx, celScope?: {}, renderContext?: {}): any;
22
+ renderEventDirect(componentJsx: TypeRenderComponentJsx, celScope: {}, renderContext: {} | undefined, eventRes: any[], next?: Function): any;
23
23
  private _collectEventActions;
24
24
  private _actionHandler;
25
25
  private _renderEventActionNormal;
26
26
  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;
27
+ render(componentJsx: TypeRenderComponent, propsInit: {} | undefined, celScope?: {}, renderContext?: {}): VNode | VNode[] | undefined;
28
+ normalizeComponenJsx(componentJsx: TypeRenderComponent, propsInit?: {}): TypeRenderComponentJsx;
33
29
  normalizeComponent(type: TypeRenderComponent): TypeRenderComponent;
34
30
  normalizeAction(type: string): string;
35
31
  private _renderJsxSingle;
36
- renderJsxProps(jsxProps: TypeRenderComponentJsxProps | undefined, props: {}, celScope: {}, renderContext: {}): {};
32
+ renderJsxProps(jsxProps: TypeRenderComponentJsxProps | undefined, props: {}, celScope?: {}, renderContext?: {}): {};
37
33
  private _renderJsxChildrenCollect;
38
- renderJsxChildrenDirect(jsxChildren: TypeRenderComponentJsx | TypeRenderComponentJsx[], celScope: {}, renderContext: {}): VNode<import("vue").RendererNode, import("vue").RendererElement, {
34
+ renderJsxChildrenDirect(jsxChildren: TypeRenderComponentJsx | TypeRenderComponentJsx[], celScope?: {}, renderContext?: {}): VNode<import("vue").RendererNode, import("vue").RendererElement, {
39
35
  [key: string]: any;
40
36
  }>[];
41
37
  }
@@ -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.26",
4
+ "gitHead": "a247f88a55c663d313296039f874560ee5a13e01",
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
  }