@micro-zoe/micro-app 0.4.1 → 0.5.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@micro-zoe/micro-app",
3
- "version": "0.4.1",
4
- "description": "A minimalist solution for building micro front-end applications",
3
+ "version": "0.5.1",
4
+ "description": "A lightweight, efficient and powerful micro front-end framework",
5
5
  "private": false,
6
6
  "main": "lib/index.min.js",
7
7
  "module": "lib/index.esm.js",
@@ -17,24 +17,24 @@
17
17
  "start:main-vue3-vite": "npm-run-all --parallel build:watch start-child:* main-vue3-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
- "install:main-react16": "cd examples/main-react16 && yarn",
21
- "install:main-vue2": "cd examples/main-vue2 && yarn",
22
- "install:main-vue3-vite": "cd examples/main-vue3-vite && yarn",
23
- "install:child-react16": "cd examples/children/react16 && yarn",
24
- "install:child-react17": "cd examples/children/react17 && yarn",
25
- "install:child-vue2": "cd examples/children/vue2 && yarn",
26
- "install:child-vue3": "cd examples/children/vue3 && yarn",
27
- "install:child-vite": "cd examples/children/vite && yarn",
28
- "install:child-angular11": "cd examples/children/angular11 && yarn",
29
- "main-react16": "cd examples/main-react16 && yarn start",
30
- "main-vue2": "cd examples/main-vue2 && yarn start",
31
- "main-vue3-vite": "cd examples/main-vue3-vite && yarn start",
32
- "start-child:react16": "cd examples/children/react16 && yarn start",
33
- "start-child:react17": "cd examples/children/react17 && yarn start",
34
- "start-child:vue2": "cd examples/children/vue2 && yarn start",
35
- "start-child:vue3": "cd examples/children/vue3 && yarn start",
36
- "start-child:vite": "cd examples/children/vite && yarn start",
37
- "start-child:angular11": "cd examples/children/angular11 && yarn start",
20
+ "install:main-react16": "cd dev/main-react16 && yarn",
21
+ "install:main-vue2": "cd dev/main-vue2 && yarn",
22
+ "install:main-vue3-vite": "cd dev/main-vue3-vite && yarn",
23
+ "install:child-react16": "cd dev/children/react16 && yarn",
24
+ "install:child-react17": "cd dev/children/react17 && yarn",
25
+ "install:child-vue2": "cd dev/children/vue2 && yarn",
26
+ "install:child-vue3": "cd dev/children/vue3 && yarn",
27
+ "install:child-vite": "cd dev/children/vite && yarn",
28
+ "install:child-angular11": "cd dev/children/angular11 && yarn",
29
+ "main-react16": "cd dev/main-react16 && yarn start",
30
+ "main-vue2": "cd dev/main-vue2 && yarn start",
31
+ "main-vue3-vite": "cd dev/main-vue3-vite && yarn start",
32
+ "start-child:react16": "cd dev/children/react16 && yarn start",
33
+ "start-child:react17": "cd dev/children/react17 && yarn start",
34
+ "start-child:vue2": "cd dev/children/vue2 && yarn start",
35
+ "start-child:vue3": "cd dev/children/vue3 && yarn start",
36
+ "start-child:vite": "cd dev/children/vite && yarn start",
37
+ "start-child:angular11": "cd dev/children/angular11 && yarn start",
38
38
  "docs": "docsify serve docs --port 2000",
39
39
  "lint": "eslint --cache '**/*.{js,ts}'",
40
40
  "lint:fix": "yarn lint --fix",
@@ -44,7 +44,7 @@
44
44
  "test": "jest",
45
45
  "test:watch": "jest --watch",
46
46
  "test:coverage": "jest --coverage",
47
- "prepublishOnly": "yarn lint && yarn build"
47
+ "prepublishOnly": "yarn lint && yarn test && yarn build"
48
48
  },
49
49
  "repository": {
50
50
  "type": "git",
@@ -82,9 +82,6 @@
82
82
  ]
83
83
  },
84
84
  "dependencies": {},
85
- "peerDependencies": {
86
- "@babel/runtime": ">=7.0.0"
87
- },
88
85
  "devDependencies": {
89
86
  "@babel/core": "~7.12.10",
90
87
  "@babel/plugin-transform-runtime": "~7.12.10",
@@ -4,40 +4,41 @@ import React from 'react';
4
4
  // lifecycles
5
5
  const eventLifeCycles = ['oncreated', 'onbeforemount', 'onmounted', 'onunmount', 'onerror', 'ondatachange'];
6
6
  function jsxCustomEvent(type, props, ...children) {
7
+ if (typeof type !== 'string' || !/^micro-app(-\S+)?/.test(type) || !props) {
8
+ return React.createElement.apply(null, [type, props, ...children]);
9
+ }
7
10
  const newProps = Object.assign({}, props);
8
- if (/^micro-app(-\S+)?/.test(type) && props) {
9
- // ref will call when create, update, unmount
10
- newProps.ref = (element) => {
11
- if (typeof props.ref === 'function') {
12
- props.ref(element);
13
- }
14
- else if (typeof props.ref === 'object') {
15
- props.ref.current = element;
11
+ // ref will call when create, update, unmount
12
+ newProps.ref = (element) => {
13
+ if (typeof props.ref === 'function') {
14
+ props.ref(element);
15
+ }
16
+ else if (typeof props.ref === 'object') {
17
+ props.ref.current = element;
18
+ }
19
+ // when unmount and update the element is null
20
+ if (element) {
21
+ // Update data when the prev and next data are different
22
+ if (toString.call(props.data) === '[object Object]' && element.data !== props.data) {
23
+ element.data = props.data;
16
24
  }
17
- // when unmount and update the element is null
18
- if (element) {
19
- // Update data when the prev and next data are different
20
- if (toString.call(props.data) === '[object Object]' && element.data !== props.data) {
21
- element.data = props.data;
22
- }
23
- for (const key in props) {
24
- if (Object.prototype.hasOwnProperty.call(props, key) &&
25
- eventLifeCycles.includes(key.toLowerCase()) &&
26
- typeof props[key] === 'function' &&
27
- (!element[key] || element[key] !== props[key])) {
28
- const eventName = key.toLowerCase().replace('on', '');
29
- if (element[key]) {
30
- // @ts-ignore
31
- element.removeEventListener(eventName, element[key], false);
32
- }
25
+ for (const key in props) {
26
+ if (Object.prototype.hasOwnProperty.call(props, key) &&
27
+ eventLifeCycles.includes(key.toLowerCase()) &&
28
+ typeof props[key] === 'function' &&
29
+ (!element[key] || element[key] !== props[key])) {
30
+ const eventName = key.toLowerCase().replace('on', '');
31
+ if (element[key]) {
33
32
  // @ts-ignore
34
- element.addEventListener(eventName, props[key], false);
35
- element[key] = props[key];
33
+ element.removeEventListener(eventName, element[key], false);
36
34
  }
35
+ // @ts-ignore
36
+ element.addEventListener(eventName, props[key], false);
37
+ element[key] = props[key];
37
38
  }
38
39
  }
39
- };
40
- }
40
+ }
41
+ };
41
42
  return React.createElement.apply(null, [type, newProps, ...children]);
42
43
  }
43
44
 
@@ -1 +1 @@
1
- {"version":3,"file":"jsx-custom-event.js","sources":["../src/polyfill/jsx-custom-event.ts"],"sourcesContent":["// @ts-ignore\nimport React from 'react'\n\ntype MicroElementType = HTMLElement & Record<string, unknown>\n\n// lifecycles\nconst eventLifeCycles = ['oncreated', 'onbeforemount', 'onmounted', 'onunmount', 'onerror', 'ondatachange']\n\nexport default function jsxCustomEvent (\n type: string | CallableFunction,\n props: Record<string, unknown> | null,\n ...children: any[]\n): void {\n const newProps = Object.assign({}, props)\n\n if (/^micro-app(-\\S+)?/.test(type as string) && props) {\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\n return React.createElement.apply(null, [type, newProps, ...children])\n}\n"],"names":[],"mappings":";;AAAA;AAKA;AACA,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,CAAC,CAAA;SAEnF,cAAc,CACpC,IAA+B,EAC/B,KAAqC,EACrC,GAAG,QAAe;IAElB,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;IAEzC,IAAI,mBAAmB,CAAC,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D,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;qBAC1B;iBACF;aACF;SACF,CAAA;KACF;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAA;AACvE;;;;"}
1
+ {"version":3,"file":"jsx-custom-event.js","sources":["../src/polyfill/jsx-custom-event.ts"],"sourcesContent":["// @ts-ignore\nimport React from 'react'\n\ntype MicroElementType = HTMLElement & Record<string, unknown>\n\n// lifecycles\nconst eventLifeCycles = ['oncreated', 'onbeforemount', 'onmounted', 'onunmount', 'onerror', 'ondatachange']\n\nexport default function 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"],"names":[],"mappings":";;AAAA;AAKA;AACA,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,eAAe,EAAE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AK,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;;;;"}
@@ -6,23 +6,14 @@ declare module '@micro-app/types' {
6
6
  type microWindowType = Window & any
7
7
 
8
8
  interface SandBoxInterface {
9
- active: boolean // sandbox state
10
9
  proxyWindow: WindowProxy
11
- recordUmdEffect: CallableFunction
12
- rebuildUmdEffect: CallableFunction
13
- releaseEffect: CallableFunction
14
- // Scoped global Properties(Properties that can only get and set in microWindow, will not escape to rawWindow)
15
- scopeProperties: Array<PropertyKey>
16
- // Properties that can be escape to rawWindow
17
- escapeProperties: Array<PropertyKey>
18
10
  microWindow: Window // Proxy target
19
- injectedKeys: Set<PropertyKey> // Properties newly added to microWindow
20
- escapeKeys: Set<PropertyKey> // Properties escape to rawWindow, cleared when unmount
21
- start(baseroute: string): void
22
- stop(): void
23
- recordUmdSnapshot(): void
24
- rebuildUmdSnapshot(): void
25
- inject(microWindow: microWindowType, appName: string, url: string): void
11
+ start (baseroute: string): void
12
+ stop (): void
13
+ // record umd snapshot before the first execution of umdHookMount
14
+ recordUmdSnapshot (): void
15
+ // rebuild umd snapshot before remount umd app
16
+ rebuildUmdSnapshot (): void
26
17
  }
27
18
 
28
19
  type sourceLinkInfo = {
@@ -39,6 +30,7 @@ declare module '@micro-app/types' {
39
30
  defer: boolean // defer script
40
31
  module: boolean // module type script
41
32
  isGlobal?: boolean // share js to global
33
+ code2Function?: Function // code to Function
42
34
  }
43
35
 
44
36
  interface sourceType {
@@ -52,6 +44,7 @@ declare module '@micro-app/types' {
52
44
  isPrefetch: boolean // whether prefetch app, default is false
53
45
  name: string // app name
54
46
  url: string // app url
47
+ ssrUrl: string // html path in ssr mode
55
48
  container: HTMLElement | ShadowRoot | null // app container
56
49
  inline: boolean // whether js runs in inline script mode, default is false
57
50
  scopecss: boolean // whether use css scoped, default is true
@@ -60,35 +53,49 @@ declare module '@micro-app/types' {
60
53
  baseroute: string // route prefix, default is ''
61
54
  source: sourceType // sources of css, js, html
62
55
  sandBox: SandBoxInterface | null // sanxbox
63
- loadSourceCode(): void // Load resources
64
- onLoad(html: HTMLElement): void // resource is loaded
65
- onLoadError(e: Error): void // Error loading HTML
66
- mount(
56
+ umdMode: boolean // is umd mode
57
+
58
+ // Load resources
59
+ loadSourceCode (): void
60
+
61
+ // resource is loaded
62
+ onLoad (html: HTMLElement): void
63
+
64
+ // Error loading HTML
65
+ onLoadError (e: Error): void
66
+
67
+ // mount app
68
+ mount (
67
69
  container?: HTMLElement | ShadowRoot,
68
70
  inline?: boolean,
69
71
  baseroute?: string,
70
- ): void // mount app
71
- dispatchMountedEvent(): void // dispatch mounted event when app run finished
72
- unmount(destory: boolean): void // unmount app
73
- onerror(e: Error): void // app rendering error
74
- getAppStatus(): string // get app status
72
+ ): void
73
+
74
+ // unmount app
75
+ unmount (destroy: boolean): void
76
+
77
+ // app rendering error
78
+ onerror (e: Error): void
79
+
80
+ // get app status
81
+ getAppStatus (): string
82
+
83
+ // actions for completely destroy
84
+ actionsForCompletelyDestory (): void
75
85
  }
76
86
 
77
87
  interface MicroAppElementType {
78
88
  appName: AttrType // app name
79
89
  appUrl: AttrType // app url
80
- isWating: boolean // combine action of set attribute name, url
81
- cacheData: Record<PropertyKey, unknown> | null // Cache data
82
- hasConnected: boolean // element has run connectedCallback
83
- connectedCallback(): void // Hooks for element append to documents
84
- disconnectedCallback(): void // Hooks for element delete from documents
85
- attributeChangedCallback(a: 'name' | 'url', o: string, n: string): void // Hooks for element attributes change
86
- handleAttributeUpdate(): void // handle for change of attribute name, url after inited
87
- legalAttribute(name: string, val: AttrType): boolean // judge the attribute is legal
88
- handleAppMount(app: AppInterface): void // mount app
89
- handleCreate(): void // create app
90
- handleUnmount (destory: boolean): void // unmount app
91
- getDisposeResult (name: string): boolean // Get configuration
90
+
91
+ // Hooks for element append to documents
92
+ connectedCallback (): void
93
+
94
+ // Hooks for element delete from documents
95
+ disconnectedCallback (): void
96
+
97
+ // Hooks for element attributes change
98
+ attributeChangedCallback (a: 'name' | 'url', o: string, n: string): void
92
99
  }
93
100
 
94
101
  type prefetchParam = {
@@ -150,7 +157,7 @@ declare module '@micro-app/types' {
150
157
  type OptionsType = {
151
158
  tagName?: string
152
159
  shadowDOM?: boolean
153
- destory?: boolean
160
+ destroy?: boolean
154
161
  inline?: boolean
155
162
  disableScopecss?: boolean
156
163
  disableSandbox?: boolean
@@ -166,7 +173,7 @@ declare module '@micro-app/types' {
166
173
  interface MicroAppConfigType {
167
174
  tagName: string
168
175
  shadowDOM?: boolean
169
- destory?: boolean
176
+ destroy?: boolean
170
177
  inline?: boolean
171
178
  disableScopecss?: boolean
172
179
  disableSandbox?: boolean
@@ -189,3 +196,7 @@ declare namespace JSX {
189
196
  }
190
197
 
191
198
  declare module '@micro-zoe/micro-app/polyfill/jsx-custom-event'
199
+
200
+ declare const __DEV__: boolean
201
+
202
+ declare const __TEST__: boolean