@lomray/react-mobx-manager 2.0.0-beta.14 → 2.0.0-beta.16
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/README.md +6 -1
- package/lib/plugins/vite/hydration-update-fix.js +1 -0
- package/lib/plugins/{id-generator.d.ts → vite/id-generator.d.ts} +4 -0
- package/lib/plugins/vite/id-generator.js +1 -0
- package/lib/plugins/{index.js → vite/index.js} +1 -1
- package/package.json +1 -1
- package/lib/plugins/hydration-update-fix.js +0 -1
- package/lib/plugins/id-generator.js +0 -1
- /package/lib/plugins/{hydration-update-fix.d.ts → vite/hydration-update-fix.d.ts} +0 -0
- /package/lib/plugins/{index.d.ts → vite/index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -80,13 +80,18 @@ module.exports = {
|
|
|
80
80
|
```typescript
|
|
81
81
|
import { defineConfig } from 'vite';
|
|
82
82
|
import react from '@vitejs/plugin-react';
|
|
83
|
-
import MobxManager from '@lomray/react-mobx-manager/plugins/index';
|
|
83
|
+
import MobxManager from '@lomray/react-mobx-manager/plugins/vite/index';
|
|
84
84
|
|
|
85
85
|
// https://vitejs.dev/config/
|
|
86
86
|
export default defineConfig({
|
|
87
87
|
plugins: [react(), MobxManager()]
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Detect mobx store:
|
|
92
|
+
- by makeObservable or makeAutoObservable
|
|
93
|
+
- by @mobx-store jsdoc before class
|
|
94
|
+
*/
|
|
90
95
|
```
|
|
91
96
|
|
|
92
97
|
## Usage
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("node:path");module.exports=function(){return{name:"@lomray/react-mobx-manager-hydration-fix",transform(r,t){const n=e.extname(t).split("?")[0];if([".js",".ts",".tsx"].includes(n)&&r.includes("function useObserver"))return{code:r.replace(/(}\);[^f]+)(forceUpdate\(\);)/s,"$1/*$2*/"),map:{mappings:""}}}}};
|
|
@@ -5,6 +5,10 @@ interface IPluginOptions {
|
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Generate unique store id's
|
|
8
|
+
*
|
|
9
|
+
* Detect mobx store:
|
|
10
|
+
* - by makeObservable or makeAutoObservable
|
|
11
|
+
* - by @mobx-store jsdoc before class
|
|
8
12
|
* @constructor
|
|
9
13
|
*/
|
|
10
14
|
declare function IdGenerator({ root, isProd }?: IPluginOptions): Plugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s=require("node:path"),e=require("node:process");const t=(s="")=>{var e;const r=s.split(""),n=null!==(e=r.pop())&&void 0!==e?e:"`";if("z"===n)return[...r,"A"].join("");if("Z"===n){const s=r.pop();return s?[t([...r,s].join("")),"a"].join(""):"aa"}return[...r,String.fromCharCode(n.charCodeAt(0)+1)].join("")};module.exports=function({root:r=e.cwd(),isProd:n=!1}={}){const o=new Map;let a="";const i=(s,e)=>{const{classname:t,storeId:r}=o.get(e),n=new RegExp(`(class\\s${t}\\s+?{)`);return s.replace(n,`$1static id = '${r}';`)};return{name:"@lomray/react-mobx-manager-id-generator",transform(e,c){const l=s.extname(c).split("?")[0];if(c.includes("node_modules")||![".js",".ts",".tsx"].includes(l)||!/(makeObservable|makeAutoObservable)\(/.test(e))return;if(o.has(c))return{code:i(e,c),map:{mappings:""}};const u=(s=>{var e,t,r,n;const{classname:o}=null!==(t=null===(e=s.match(/class\s(?<classname>\w+)\s+?{(?!.*static\sid\s*=.*).+(makeObservable|makeAutoObservable)(?!.*persistStore\(\1.*)/s))||void 0===e?void 0:e.groups)&&void 0!==t?t:{};if(o)return o;const{classname:a}=null!==(n=null===(r=s.match(/(@mobx-store).+class\s(?<classname>\w+)\s+?{(?!.*static\sid\s*=.*).+}(?!.*persistStore.*)/s))||void 0===r?void 0:r.groups)&&void 0!==n?n:{};return a})(e);if(u){if(!o.has(c)){const s=n?(()=>{const s=t(a),e=`S-${s}`;return a=s,e})():((s,e)=>`${s.replace(r,"").replace(/\/index.(js|ts|tsx)/,"").split("/").filter(Boolean).join("-")}-${e}`)(c,u);o.set(c,{classname:u,storeId:s})}return{code:i(e,c),map:{mappings:""}}}}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("node:process"),r=require("./hydration-update-fix.js"),t=require("./id-generator.js");function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var n=o(e);
|
|
1
|
+
"use strict";var e=require("node:process"),r=require("./hydration-update-fix.js"),t=require("./id-generator.js");function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var n=o(e);module.exports=function(){let e;return[r(),{name:t().name,configResolved({root:r}){var o;e=t({root:r,isProd:"production"===o||"production"===n.env.NODE_ENV})},transform(...r){var t;return null===(t=e.transform)||void 0===t?void 0:t.call(this,...r)}}]};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";module.exports=function(){return{name:"@lomray/react-mobx-manager-hydration-fix",transform(e){if(e.includes("function useObserver"))return{code:e.replace(/(}\);[^f]+)(forceUpdate\(\);)/s,"$1/*$2*/"),map:{mappings:""}}}}};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("node:path"),s=require("node:process");const t=(e="")=>{var s;const r=e.split(""),a=null!==(s=r.pop())&&void 0!==s?s:"`";if("z"===a)return[...r,"A"].join("");if("Z"===a){const e=r.pop();return e?[t([...r,e].join("")),"a"].join(""):"aa"}return[...r,String.fromCharCode(a.charCodeAt(0)+1)].join("")};module.exports=function({root:r=s.cwd(),isProd:a=!1}={}){const n=new Map;let o="";const i=(e,s)=>{const{classname:t,storeId:r}=n.get(s),a=new RegExp(`(class\\s${t}\\s+?{)`);return e.replace(a,`$1static id = '${r}';`)};return{name:"@lomray/react-mobx-manager-id-generator",transform(s,c){var l,d;const u=e.extname(c);if(c.includes("node_modules")||![".js",".ts",".tsx"].includes(u)||!/(makeObservable|makeAutoObservable)\(/.test(s))return;if(n.has(c))return{code:i(s,c),map:{mappings:""}};const{classname:m,staticId:p}=null!==(d=null===(l=s.match(/class\s(?<classname>\w+)\s+?{(?<staticId>.+(static\sid[^=]+=))?.+(makeObservable|makeAutoObservable)/s))||void 0===l?void 0:l.groups)&&void 0!==d?d:{};if(!p&&m){if(!n.has(c)){const e=a?"":c.replace(r,"").replace(/\/index.(js|ts|tsx)/,"").split("/").filter(Boolean).join("-"),s=a?(()=>{const e=t(o),s=`S-${e}`;return o=e,s})():`${e}-${m}`;n.set(c,{classname:m,storeId:s})}return{code:i(s,c),map:{mappings:""}}}}}};
|
|
File without changes
|
|
File without changes
|