@salt-ds/styles 0.1.1 → 0.1.2
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.
|
@@ -26,7 +26,7 @@ function _interopNamespace(e) {
|
|
|
26
26
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
27
27
|
|
|
28
28
|
var _a;
|
|
29
|
-
const maybeUseInsertionEffect = (_a = React__namespace[
|
|
29
|
+
const maybeUseInsertionEffect = (_a = React__namespace["useInsertionEffect".toString()]) != null ? _a : React__namespace.useLayoutEffect;
|
|
30
30
|
const windowSheetsMap = /* @__PURE__ */ new WeakMap();
|
|
31
31
|
function useComponentCssInjection({
|
|
32
32
|
testId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStyleInjection.js","sources":["../src/use-style-injection/useStyleInjection.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useInsertionPoint } from \"./InsertionPointProvider\";\n\n/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment -- Workaround for https://github.com/webpack/webpack/issues/14814 */\nconst maybeUseInsertionEffect: typeof React.useLayoutEffect =\n (React as any)[
|
|
1
|
+
{"version":3,"file":"useStyleInjection.js","sources":["../src/use-style-injection/useStyleInjection.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useInsertionPoint } from \"./InsertionPointProvider\";\n\n/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any -- Workaround for https://github.com/webpack/webpack/issues/14814#issuecomment-1536757985 */\nconst maybeUseInsertionEffect: typeof React.useLayoutEffect =\n (React as any)[\"useInsertionEffect\".toString()] ?? React.useLayoutEffect;\n/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment */\n\nexport interface UseComponentCssInjection {\n testId?: string;\n css: string;\n window?: Window | null;\n}\n\ntype StyleElementMap = Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n>;\n\n// windowSheetsMap maps window objects to StyleElementMaps\n// A StyleElementMap maps css strings to style element tags\nconst windowSheetsMap = new WeakMap<Window, StyleElementMap>();\n\nexport function useComponentCssInjection({\n testId,\n css,\n window: targetWindow,\n}: UseComponentCssInjection): void {\n const insertionPoint = useInsertionPoint();\n\n maybeUseInsertionEffect(() => {\n if (!targetWindow) {\n return;\n }\n\n const sheetsMap =\n windowSheetsMap.get(targetWindow) ??\n new Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n >();\n const styleMap = sheetsMap.get(css) ?? { styleElement: null, count: 0 };\n\n if (styleMap.styleElement == null) {\n styleMap.styleElement = targetWindow.document.createElement(\"style\");\n styleMap.styleElement.setAttribute(\"type\", \"text/css\");\n styleMap.styleElement.setAttribute(\"data-salt-style\", testId || \"\");\n styleMap.styleElement.textContent = css;\n\n styleMap.count = 1;\n\n targetWindow.document.head.insertBefore(\n styleMap.styleElement,\n insertionPoint || targetWindow.document.head.firstChild\n );\n } else {\n styleMap.styleElement.textContent = css;\n styleMap.count++;\n }\n sheetsMap.set(css, styleMap);\n windowSheetsMap.set(targetWindow, sheetsMap);\n\n return () => {\n const sheetsMap = windowSheetsMap.get(targetWindow);\n const styleMap = sheetsMap?.get(css);\n if (styleMap?.styleElement) {\n styleMap.count--;\n if (styleMap.count < 1) {\n targetWindow.document.head.removeChild(styleMap.styleElement);\n styleMap.styleElement = null;\n sheetsMap?.delete(css);\n }\n }\n };\n }, [testId, css, targetWindow]);\n}\n"],"names":["React","useInsertionPoint","_a","sheetsMap","styleMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,EAAA,CAAA;AAIA,MAAM,2BACH,EAAc,GAAAA,gBAAA,CAAA,oBAAA,CAAqB,QAAS,EAAA,CAAA,KAA5C,YAAkDA,gBAAM,CAAA,eAAA,CAAA;AAgB3D,MAAM,eAAA,uBAAsB,OAAiC,EAAA,CAAA;AAEtD,SAAS,wBAAyB,CAAA;AA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S,QAAA,CAAA,KAAA,EAAA,CAAA;AAAA,KACX;AACA,IAAU,SAAA,CAAA,GAAA,CAAI,KAAK,QAAQ,CAAA,CAAA;AAC3B,IAAgB,eAAA,CAAA,GAAA,CAAI,cAAc,SAAS,CAAA,CAAA;AAE3C,IAAA,OAAO,MAAM;AACX,MAAMC,MAAAA,UAAAA,GAAY,eAAgB,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAClD,MAAA,MAAMC,SAAWD,GAAAA,UAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAAA,CAAW,GAAI,CAAA,GAAA,CAAA,CAAA;AAChC,MAAIC,IAAAA,SAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,SAAAA,CAAU,YAAc,EAAA;AAC1B,QAAAA,SAAS,CAAA,KAAA,EAAA,CAAA;AACT,QAAIA,IAAAA,SAAAA,CAAS,QAAQ,CAAG,EAAA;AACtB,UAAA,YAAA,CAAa,QAAS,CAAA,IAAA,CAAK,WAAYA,CAAAA,SAAAA,CAAS,YAAY,CAAA,CAAA;AAC5D,UAAAA,UAAS,YAAe,GAAA,IAAA,CAAA;AACxB,UAAAD,UAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAAA,CAAW,MAAO,CAAA,GAAA,CAAA,CAAA;AAAA,SACpB;AAAA,OACF;AAAA,KACF,CAAA;AAAA,GACC,EAAA,CAAC,MAAQ,EAAA,GAAA,EAAK,YAAY,CAAC,CAAA,CAAA;AAChC;;;;"}
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { useInsertionPoint } from './InsertionPointProvider.js';
|
|
3
3
|
|
|
4
4
|
var _a;
|
|
5
|
-
const maybeUseInsertionEffect = (_a = React[
|
|
5
|
+
const maybeUseInsertionEffect = (_a = React["useInsertionEffect".toString()]) != null ? _a : React.useLayoutEffect;
|
|
6
6
|
const windowSheetsMap = /* @__PURE__ */ new WeakMap();
|
|
7
7
|
function useComponentCssInjection({
|
|
8
8
|
testId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStyleInjection.js","sources":["../src/use-style-injection/useStyleInjection.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useInsertionPoint } from \"./InsertionPointProvider\";\n\n/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment -- Workaround for https://github.com/webpack/webpack/issues/14814 */\nconst maybeUseInsertionEffect: typeof React.useLayoutEffect =\n (React as any)[
|
|
1
|
+
{"version":3,"file":"useStyleInjection.js","sources":["../src/use-style-injection/useStyleInjection.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useInsertionPoint } from \"./InsertionPointProvider\";\n\n/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any -- Workaround for https://github.com/webpack/webpack/issues/14814#issuecomment-1536757985 */\nconst maybeUseInsertionEffect: typeof React.useLayoutEffect =\n (React as any)[\"useInsertionEffect\".toString()] ?? React.useLayoutEffect;\n/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment */\n\nexport interface UseComponentCssInjection {\n testId?: string;\n css: string;\n window?: Window | null;\n}\n\ntype StyleElementMap = Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n>;\n\n// windowSheetsMap maps window objects to StyleElementMaps\n// A StyleElementMap maps css strings to style element tags\nconst windowSheetsMap = new WeakMap<Window, StyleElementMap>();\n\nexport function useComponentCssInjection({\n testId,\n css,\n window: targetWindow,\n}: UseComponentCssInjection): void {\n const insertionPoint = useInsertionPoint();\n\n maybeUseInsertionEffect(() => {\n if (!targetWindow) {\n return;\n }\n\n const sheetsMap =\n windowSheetsMap.get(targetWindow) ??\n new Map<\n string,\n { styleElement: HTMLStyleElement | null; count: number }\n >();\n const styleMap = sheetsMap.get(css) ?? { styleElement: null, count: 0 };\n\n if (styleMap.styleElement == null) {\n styleMap.styleElement = targetWindow.document.createElement(\"style\");\n styleMap.styleElement.setAttribute(\"type\", \"text/css\");\n styleMap.styleElement.setAttribute(\"data-salt-style\", testId || \"\");\n styleMap.styleElement.textContent = css;\n\n styleMap.count = 1;\n\n targetWindow.document.head.insertBefore(\n styleMap.styleElement,\n insertionPoint || targetWindow.document.head.firstChild\n );\n } else {\n styleMap.styleElement.textContent = css;\n styleMap.count++;\n }\n sheetsMap.set(css, styleMap);\n windowSheetsMap.set(targetWindow, sheetsMap);\n\n return () => {\n const sheetsMap = windowSheetsMap.get(targetWindow);\n const styleMap = sheetsMap?.get(css);\n if (styleMap?.styleElement) {\n styleMap.count--;\n if (styleMap.count < 1) {\n targetWindow.document.head.removeChild(styleMap.styleElement);\n styleMap.styleElement = null;\n sheetsMap?.delete(css);\n }\n }\n };\n }, [testId, css, targetWindow]);\n}\n"],"names":["_a","sheetsMap","styleMap"],"mappings":";;;AAAA,IAAA,EAAA,CAAA;AAIA,MAAM,2BACH,EAAc,GAAA,KAAA,CAAA,oBAAA,CAAqB,QAAS,EAAA,CAAA,KAA5C,YAAkD,KAAM,CAAA,eAAA,CAAA;AAgB3D,MAAM,eAAA,uBAAsB,OAAiC,EAAA,CAAA;AAEtD,SAAS,wBAAyB,CAAA;AAAA,EACvC,MAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAQ,EAAA,YAAA;AACV,CAAmC,EAAA;AACjC,EAAA,MAAM,iBAAiB,iBAAkB,EAAA,CAAA;AAEzC,EAAA,uBAAA,CAAwB,MAAM;AA9BhC,IAAA,IAAAA,GAAA,EAAA,EAAA,CAAA;AA+BI,IAAA,IAAI,CAAC,YAAc,EAAA;AACjB,MAAA,OAAA;AAAA,KACF;AAEA,IAAM,MAAA,SAAA,GAAA,CACJA,MAAA,eAAgB,CAAA,GAAA,CAAI,YAAY,CAAhC,KAAA,IAAA,GAAAA,GACA,mBAAA,IAAI,GAGF,EAAA,CAAA;AACJ,IAAM,MAAA,QAAA,GAAA,CAAW,EAAU,GAA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GAAAA,SAAAA,CAAU,YAAc,EAAA;AAC1B,QAAAA,SAAS,CAAA,KAAA,EAAA,CAAA;AACT,QAAIA,IAAAA,SAAAA,CAAS,QAAQ,CAAG,EAAA;AACtB,UAAA,YAAA,CAAa,QAAS,CAAA,IAAA,CAAK,WAAYA,CAAAA,SAAAA,CAAS,YAAY,CAAA,CAAA;AAC5D,UAAAA,UAAS,YAAe,GAAA,IAAA,CAAA;AACxB,UAAAD,UAAAA,IAAA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAAA,CAAW,MAAO,CAAA,GAAA,CAAA,CAAA;AAAA,SACpB;AAAA,OACF;AAAA,KACF,CAAA;AAAA,GACC,EAAA,CAAC,MAAQ,EAAA,GAAA,EAAK,YAAY,CAAC,CAAA,CAAA;AAChC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salt-ds/styles",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/jpmorganchase/salt-ds.git",
|
|
8
|
+
"directory": "packages/styles"
|
|
9
|
+
},
|
|
10
|
+
"bugs": "https://github.com/jpmorganchase/salt-ds/issues",
|
|
5
11
|
"main": "dist-cjs/index.js",
|
|
6
12
|
"sideEffects": false,
|
|
7
13
|
"peerDependencies": {
|
|
@@ -26,10 +32,5 @@
|
|
|
26
32
|
"dist-es",
|
|
27
33
|
"dist-types",
|
|
28
34
|
"README.md"
|
|
29
|
-
]
|
|
30
|
-
"repository": {
|
|
31
|
-
"type": "git",
|
|
32
|
-
"url": "https://github.com/jpmorganchase/salt-ds",
|
|
33
|
-
"directory": "packages/styles"
|
|
34
|
-
}
|
|
35
|
+
]
|
|
35
36
|
}
|