@micro-zoe/micro-app 0.5.3 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micro-zoe/micro-app",
3
- "version": "0.5.3",
3
+ "version": "0.7.0",
4
4
  "description": "A lightweight, efficient and powerful micro front-end framework",
5
5
  "private": false,
6
6
  "main": "lib/index.min.js",
@@ -14,12 +14,12 @@
14
14
  "start": "yarn start:main-react16",
15
15
  "start:main-react16": "npm-run-all --parallel build:watch start-child:* main-react16",
16
16
  "start:main-vue2": "npm-run-all --parallel build:watch start-child:* main-vue2",
17
- "start:main-vue3-vite": "npm-run-all --parallel build:watch start-child:* main-vue3-vite",
17
+ "start:main-vite": "npm-run-all --parallel build:watch start-child:* main-vite",
18
18
  "build:watch": "cross-env NODE_ENV='development' rollup -c -w",
19
19
  "build": "cross-env NODE_ENV='production' rollup -c && npm run createtype && npm run afterbuild",
20
20
  "install:main-react16": "cd dev/main-react16 && yarn",
21
21
  "install:main-vue2": "cd dev/main-vue2 && yarn",
22
- "install:main-vue3-vite": "cd dev/main-vue3-vite && yarn",
22
+ "install:main-vite": "cd dev/main-vite && yarn",
23
23
  "install:child-react16": "cd dev/children/react16 && yarn",
24
24
  "install:child-react17": "cd dev/children/react17 && yarn",
25
25
  "install:child-vue2": "cd dev/children/vue2 && yarn",
@@ -28,7 +28,7 @@
28
28
  "install:child-angular11": "cd dev/children/angular11 && yarn",
29
29
  "main-react16": "cd dev/main-react16 && yarn start",
30
30
  "main-vue2": "cd dev/main-vue2 && yarn start",
31
- "main-vue3-vite": "cd dev/main-vue3-vite && yarn start",
31
+ "main-vite": "cd dev/main-vite && yarn start",
32
32
  "start-child:react16": "cd dev/children/react16 && yarn start",
33
33
  "start-child:react17": "cd dev/children/react17 && yarn start",
34
34
  "start-child:vue2": "cd dev/children/vue2 && yarn start",
@@ -1,6 +1,16 @@
1
1
  const React = require('react');
2
2
  // lifecycles
3
- const eventLifeCycles = ['oncreated', 'onbeforemount', 'onmounted', 'onunmount', 'onerror', 'ondatachange'];
3
+ const eventLifeCycles = [
4
+ 'oncreated',
5
+ 'onbeforemount',
6
+ 'onmounted',
7
+ 'onunmount',
8
+ 'onerror',
9
+ 'ondatachange',
10
+ 'onbeforeshow',
11
+ 'onaftershow',
12
+ 'onafterhidden',
13
+ ];
4
14
  function jsxCustomEvent(type, props, ...children) {
5
15
  if (typeof type !== 'string' || !/^micro-app(-\S+)?/.test(type) || !props) {
6
16
  return React.createElement.apply(null, [type, props, ...children]);
@@ -1 +1 @@
1
- {"version":3,"file":"jsx-custom-event.js","sources":["../src/polyfill/jsx-custom-event.ts"],"sourcesContent":["const React = require('react')\n\ntype MicroElementType = HTMLElement & Record<string, unknown>\n\n// lifecycles\nconst eventLifeCycles = ['oncreated', 'onbeforemount', 'onmounted', 'onunmount', 'onerror', 'ondatachange']\n\nfunction jsxCustomEvent (\n type: string | CallableFunction,\n props: Record<string, unknown> | null,\n ...children: any[]\n): void {\n if (typeof type !== 'string' || !/^micro-app(-\\S+)?/.test(type as string) || !props) {\n return React.createElement.apply(null, [type, props, ...children])\n }\n\n const newProps = Object.assign({}, props)\n\n // ref will call when create, update, unmount\n newProps.ref = (element: MicroElementType | null) => {\n if (typeof props.ref === 'function') {\n props.ref(element)\n } else if (typeof props.ref === 'object') {\n (props.ref as any).current = element\n }\n\n // when unmount and update the element is null\n if (element) {\n // Update data when the prev and next data are different\n if (toString.call(props.data) === '[object Object]' && element.data !== props.data) {\n element.data = props.data\n }\n\n for (const key in props) {\n if (\n Object.prototype.hasOwnProperty.call(props, key) &&\n eventLifeCycles.includes(key.toLowerCase()) &&\n typeof props[key] === 'function' &&\n (!element[key] || element[key] !== props[key])\n ) {\n const eventName = key.toLowerCase().replace('on', '')\n if (element[key]) {\n // @ts-ignore\n element.removeEventListener(eventName, element[key], false)\n }\n // @ts-ignore\n element.addEventListener(eventName, props[key], false)\n element[key] = props[key]\n }\n }\n }\n }\n\n return React.createElement.apply(null, [type, newProps, ...children])\n}\n\nmodule.exports = jsxCustomEvent\nmodule.exports.default = jsxCustomEvent\n"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAI9B;AACA,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,CAAC,CAAA;AAE3G,SAAS,cAAc,CACrB,IAA+B,EAC/B,KAAqC,EACrC,GAAG,QAAe;IAElB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAc,CAAC,IAAI,CAAC,KAAK,EAAE;QACnF,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAA;KACnE;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;;IAGzC,QAAQ,CAAC,GAAG,GAAG,CAAC,OAAgC;QAC9C,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,UAAU,EAAE;YACnC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;SACnB;aAAM,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE;YACvC,KAAK,CAAC,GAAW,CAAC,OAAO,GAAG,OAAO,CAAA;SACrC;;QAGD,IAAI,OAAO,EAAE;;YAEX,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,iBAAiB,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE;gBAClF,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;aAC1B;YAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;gBACvB,IACE,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC;oBAChD,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;oBAC3C,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,UAAU;qBAC/B,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,CAAC,EAC9C;oBACA,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;oBACrD,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE;;wBAEhB,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;qBAC5D;;oBAED,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;oBACtD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;iBAC1B;aACF;SACF;KACF,CAAA;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAA;AACvE,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,cAAc,CAAA;AAC/B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,cAAc"}
1
+ {"version":3,"file":"jsx-custom-event.js","sources":["../src/polyfill/jsx-custom-event.ts"],"sourcesContent":["const React = require('react')\n\ntype MicroElementType = HTMLElement & Record<string, unknown>\n\n// lifecycles\nconst eventLifeCycles = [\n 'oncreated',\n 'onbeforemount',\n 'onmounted',\n 'onunmount',\n 'onerror',\n 'ondatachange',\n 'onbeforeshow',\n 'onaftershow',\n 'onafterhidden',\n]\n\nfunction jsxCustomEvent (\n type: string | CallableFunction,\n props: Record<string, unknown> | null,\n ...children: any[]\n): void {\n if (typeof type !== 'string' || !/^micro-app(-\\S+)?/.test(type) || !props) {\n return React.createElement.apply(null, [type, props, ...children])\n }\n\n const newProps = Object.assign({}, props)\n\n // ref will call when create, update, unmount\n newProps.ref = (element: MicroElementType | null) => {\n if (typeof props.ref === 'function') {\n props.ref(element)\n } else if (typeof props.ref === 'object') {\n (props.ref as any).current = element\n }\n\n // when unmount and update the element is null\n if (element) {\n // Update data when the prev and next data are different\n if (toString.call(props.data) === '[object Object]' && element.data !== props.data) {\n element.data = props.data\n }\n\n for (const key in props) {\n if (\n Object.prototype.hasOwnProperty.call(props, key) &&\n eventLifeCycles.includes(key.toLowerCase()) &&\n typeof props[key] === 'function' &&\n (!element[key] || element[key] !== props[key])\n ) {\n const eventName = key.toLowerCase().replace('on', '')\n if (element[key]) {\n // @ts-ignore\n element.removeEventListener(eventName, element[key], false)\n }\n // @ts-ignore\n element.addEventListener(eventName, props[key], false)\n element[key] = props[key]\n }\n }\n }\n }\n\n return React.createElement.apply(null, [type, newProps, ...children])\n}\n\nmodule.exports = jsxCustomEvent\nmodule.exports.default = jsxCustomEvent\n"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAI9B;AACA,MAAM,eAAe,GAAG;IACtB,WAAW;IACX,eAAe;IACf,WAAW;IACX,WAAW;IACX,SAAS;IACT,cAAc;IACd,cAAc;IACd,aAAa;IACb,eAAe;CAChB,CAAA;AAED,SAAS,cAAc,CACrB,IAA+B,EAC/B,KAAqC,EACrC,GAAG,QAAe;IAElB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;QACzE,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC,CA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AAG,CAAC,EAAE,KAAK,CAAC,CAAA;oBACtD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;iBAC1B;aACF;SACF;KACF,CAAA;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAA;AACvE,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,cAAc,CAAA;AAC/B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,cAAc"}
@@ -3,11 +3,11 @@ declare module '@micro-app/types' {
3
3
 
4
4
  type Func = (...rest: any[]) => void
5
5
 
6
- type microWindowType = Window & any
6
+ type microAppWindowType = Window & any
7
7
 
8
8
  interface SandBoxInterface {
9
9
  proxyWindow: WindowProxy
10
- microWindow: Window // Proxy target
10
+ microAppWindow: Window // Proxy target
11
11
  start (baseroute: string): void
12
12
  stop (): void
13
13
  // record umd snapshot before the first execution of umdHookMount
@@ -45,11 +45,10 @@ declare module '@micro-app/types' {
45
45
  name: string // app name
46
46
  url: string // app url
47
47
  ssrUrl: string // html path in ssr mode
48
- container: HTMLElement | ShadowRoot | null // app container
48
+ container: HTMLElement | ShadowRoot | null // container maybe null, micro-app, shadowRoot, DIV(keep-alive)
49
49
  inline: boolean // whether js runs in inline script mode, default is false
50
50
  scopecss: boolean // whether use css scoped, default is true
51
51
  useSandbox: boolean // whether use js sandbox, default is true
52
- macro: boolean // used to solve the async render problem of vue3, default is false
53
52
  baseroute: string // route prefix, default is ''
54
53
  source: sourceType // sources of css, js, html
55
54
  sandBox: SandBoxInterface | null // sanxbox
@@ -72,16 +71,24 @@ declare module '@micro-app/types' {
72
71
  ): void
73
72
 
74
73
  // unmount app
75
- unmount (destroy: boolean): void
74
+ unmount (destroy: boolean, unmountcb?: CallableFunction): void
76
75
 
77
76
  // app rendering error
78
77
  onerror (e: Error): void
79
78
 
80
- // get app status
81
- getAppStatus (): string
79
+ // get app state
80
+ getAppState (): string
81
+
82
+ getKeepAliveState(): string | null
82
83
 
83
84
  // actions for completely destroy
84
- actionsForCompletelyDestory (): void
85
+ actionsForCompletelyDestroy (): void
86
+
87
+ // hidden app when disconnectedCallback with keep-alive
88
+ hiddenKeepAliveApp (): void
89
+
90
+ // show app when connectedCallback with keep-alive
91
+ showKeepAliveApp (container: HTMLElement | ShadowRoot): void
85
92
  }
86
93
 
87
94
  interface MicroAppElementType {
@@ -103,7 +110,6 @@ declare module '@micro-app/types' {
103
110
  url: string,
104
111
  disableScopecss?: boolean
105
112
  disableSandbox?: boolean
106
- macro?: boolean
107
113
  shadowDOM?: boolean
108
114
  }
109
115
 
@@ -161,7 +167,6 @@ declare module '@micro-app/types' {
161
167
  inline?: boolean
162
168
  disableScopecss?: boolean
163
169
  disableSandbox?: boolean
164
- macro?: boolean
165
170
  ssr?: boolean
166
171
  lifeCycles?: lifeCyclesType
167
172
  preFetchApps?: prefetchParamList
@@ -178,7 +183,6 @@ declare module '@micro-app/types' {
178
183
  inline?: boolean
179
184
  disableScopecss?: boolean
180
185
  disableSandbox?: boolean
181
- macro?: boolean
182
186
  ssr?: boolean
183
187
  lifeCycles?: lifeCyclesType
184
188
  plugins?: plugins