@tooltify/integration-shared 0.1.4 → 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 CHANGED
@@ -1,5 +1,11 @@
1
- interface StartOptions {
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
- export type { StartOptions };
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
- declare function jsxDEV(type: any, props: any, key: any, isStaticChildren: boolean, source?: {
5
- fileName?: string;
6
- lineNumber?: number;
7
- columnNumber?: number;
8
- }): react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
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 { jsxDEV };
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
- var SymbolForwardRef = /* @__PURE__ */ Symbol.for("react.forward_ref");
9
- var isForwardRef = (type) => (
10
- /**
11
- * Este check solo sera aplicado apartir de react < 16.3
12
- */
13
- typeof type === "object" && type !== null && type?.["$$typeof"] === SymbolForwardRef
14
- );
15
- function jsxDEV(type, props, key, isStaticChildren, source) {
16
- if ((typeof type === "string" || isForwardRef(type)) && source?.fileName) {
17
- const idx = source.fileName.indexOf(__TOOLTIFY_PACKAGES_DIR__);
18
- if (idx >= 0) {
19
- const relative = source.fileName.slice(idx + __TOOLTIFY_PACKAGES_DIR__.length);
20
- const sourceValue = `${relative}:${source.lineNumber ?? 0}`;
21
- const originalRef = props.ref;
22
- props.ref = (el) => {
23
- if (el) el.setAttribute(SOURCE_PROPERTY_NAME, sourceValue);
24
- if (typeof originalRef === "function") originalRef(el);
25
- else if (originalRef && "current" in originalRef) originalRef.current = el;
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
- const fn = isStaticChildren ? _jsxs : _jsx;
30
- return fn(type, props, key);
30
+ return { jsxDEV, Fragment };
31
31
  }
32
32
  export {
33
- Fragment,
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.1.4",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -12,8 +12,8 @@
12
12
  "./source-transformers/react": {
13
13
  "types": "./dist/source-transformers/react.d.ts",
14
14
  "import": "./dist/source-transformers/react.js",
15
- "default": "./dist/source-transformers/react.js",
16
- "require": "./dist/source-transformers/react.js"
15
+ "require": "./dist/source-transformers/react.js",
16
+ "default": "./dist/source-transformers/react.js"
17
17
  }
18
18
  },
19
19
  "scripts": {
@@ -21,8 +21,7 @@
21
21
  "prepublishOnly": "npm run build"
22
22
  },
23
23
  "peerDependencies": {
24
- "react": "*",
25
- "@tooltify/core": "*"
24
+ "react": "*"
26
25
  },
27
26
  "files": [
28
27
  "dist"