@tooltify/integration-shared 0.1.3 → 0.2.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/dist/index.d.ts +8 -2
- package/dist/index.js +18 -0
- package/dist/source-transformers/react.d.ts +16 -7
- package/dist/source-transformers/react.js +22 -23
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
interface
|
|
1
|
+
interface ReactOptions {
|
|
2
|
+
shouldInjectSource?: (type: any, props: any) => boolean;
|
|
3
|
+
}
|
|
4
|
+
interface BaseStartOptions {
|
|
2
5
|
publicUrl?: string;
|
|
6
|
+
react?: ReactOptions;
|
|
3
7
|
}
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
declare function createReactJsxRuntimeFile(packagesDir: string, shouldInjectSource?: (type: any, props: any) => boolean): string;
|
|
10
|
+
|
|
11
|
+
export { type BaseStartOptions, type ReactOptions, createReactJsxRuntimeFile };
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// helpers/createReactJsxRuntimeFile.helper.ts
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
var _require = createRequire(import.meta.url);
|
|
4
|
+
var REACT_TRANSFORMER_PATH = _require.resolve("@tooltify/integration-shared/source-transformers/react");
|
|
5
|
+
console.log(REACT_TRANSFORMER_PATH);
|
|
6
|
+
function createReactJsxRuntimeFile(packagesDir, shouldInjectSource) {
|
|
7
|
+
const shouldInjectSourceCode = shouldInjectSource ? shouldInjectSource.toString() : "undefined";
|
|
8
|
+
const isShortMethodDefinition = shouldInjectSourceCode.startsWith("shouldInjectSource");
|
|
9
|
+
return `import { createJsxRuntime } from ${JSON.stringify(REACT_TRANSFORMER_PATH)}
|
|
10
|
+
export const { jsxDEV, Fragment } = createJsxRuntime({
|
|
11
|
+
packagesDir: ${JSON.stringify(packagesDir)},
|
|
12
|
+
${isShortMethodDefinition ? "" : "shouldInjectSource:"}${shouldInjectSourceCode}
|
|
13
|
+
})
|
|
14
|
+
`;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
createReactJsxRuntimeFile
|
|
18
|
+
};
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
export { Fragment } from 'react/jsx-runtime';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
interface JsxRuntimeOptions {
|
|
4
|
+
packagesDir: string;
|
|
5
|
+
shouldInjectSource?: (type: any, props: any) => boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Esto reescribe la libreria de JSXRuntime agregando un wrapper para poder inyectar el data-source.
|
|
9
|
+
*/
|
|
10
|
+
declare function createJsxRuntime({ packagesDir, shouldInjectSource }: JsxRuntimeOptions): {
|
|
11
|
+
jsxDEV: (type: any, props: any, key: any, isStaticChildren: boolean, source?: {
|
|
12
|
+
fileName?: string;
|
|
13
|
+
lineNumber?: number;
|
|
14
|
+
columnNumber?: number;
|
|
15
|
+
}) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
16
|
+
Fragment: react.ExoticComponent<react.FragmentProps>;
|
|
17
|
+
};
|
|
9
18
|
|
|
10
|
-
export {
|
|
19
|
+
export { type JsxRuntimeOptions, createJsxRuntime };
|
|
@@ -5,31 +5,30 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment } from "react/jsx-runtime";
|
|
|
5
5
|
var SOURCE_PROPERTY_NAME = "tooltify_source";
|
|
6
6
|
|
|
7
7
|
// source-transformers/react.source-transformer.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
8
|
+
function createJsxRuntime({ packagesDir, shouldInjectSource }) {
|
|
9
|
+
const shouldInject = (type, props) => {
|
|
10
|
+
if (typeof type === "string") return true;
|
|
11
|
+
return shouldInjectSource?.(type, props) ?? false;
|
|
12
|
+
};
|
|
13
|
+
function jsxDEV(type, props, key, isStaticChildren, source) {
|
|
14
|
+
if (shouldInject(type, props) && source?.fileName) {
|
|
15
|
+
const idx = source.fileName.indexOf(packagesDir);
|
|
16
|
+
if (idx >= 0) {
|
|
17
|
+
const relative = source.fileName.slice(idx + packagesDir.length);
|
|
18
|
+
const sourceValue = `${relative}:${source.lineNumber ?? 0}`;
|
|
19
|
+
const originalRef = props.ref;
|
|
20
|
+
props.ref = (el) => {
|
|
21
|
+
if (el && typeof el.setAttribute === "function") el.setAttribute(SOURCE_PROPERTY_NAME, sourceValue);
|
|
22
|
+
if (typeof originalRef === "function") originalRef(el);
|
|
23
|
+
else if (originalRef && "current" in originalRef) originalRef.current = el;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
27
26
|
}
|
|
27
|
+
const fn = isStaticChildren ? _jsxs : _jsx;
|
|
28
|
+
return fn(type, props, key);
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
return fn(type, props, key);
|
|
30
|
+
return { jsxDEV, Fragment };
|
|
31
31
|
}
|
|
32
32
|
export {
|
|
33
|
-
|
|
34
|
-
jsxDEV
|
|
33
|
+
createJsxRuntime
|
|
35
34
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tooltify/integration-shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"./source-transformers/react": {
|
|
13
13
|
"types": "./dist/source-transformers/react.d.ts",
|
|
14
14
|
"import": "./dist/source-transformers/react.js",
|
|
15
|
+
"require": "./dist/source-transformers/react.js",
|
|
15
16
|
"default": "./dist/source-transformers/react.js"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
@@ -20,8 +21,7 @@
|
|
|
20
21
|
"prepublishOnly": "npm run build"
|
|
21
22
|
},
|
|
22
23
|
"peerDependencies": {
|
|
23
|
-
"react": "*"
|
|
24
|
-
"@tooltify/core": "*"
|
|
24
|
+
"react": "*"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"dist"
|