@servicetitan/ko-bridge 34.3.0-beta.2 → 35.0.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ko-binding-handlers.d.ts","sourceRoot":"","sources":["../src/ko-binding-handlers.tsx"],"names":[],"mappings":"AAIA,KAAK,EAAE,GAAG,cAAc,UAAU,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ko-binding-handlers.d.ts","sourceRoot":"","sources":["../src/ko-binding-handlers.tsx"],"names":[],"mappings":"AAIA,KAAK,EAAE,GAAG,cAAc,UAAU,CAAC,CAAC;AAapC,eAAO,MAAM,iBAAiB;4BAEF,EAAE,KAAG,sBAAsB;gBAsBvC,EAAE,KAAG,sBAAsB;CAqB1C,CAAC"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Fragment, useEffect } from 'react';
|
|
3
3
|
import ReactDOM from 'react-dom';
|
|
4
|
-
|
|
4
|
+
let createRoot;
|
|
5
|
+
try {
|
|
6
|
+
/**
|
|
7
|
+
* Note, the webpack.IgnorePlugin must be configured to ignore this dependency.
|
|
8
|
+
* @see {@link file://./../../startup/src/webpack/configs/plugins/ignore-plugin/ignore-plugin.ts}
|
|
9
|
+
*/ createRoot = require('react-dom/client').createRoot;
|
|
10
|
+
} catch (unused) {
|
|
11
|
+
// ignore
|
|
12
|
+
}
|
|
5
13
|
export const koBindingHandlers = {
|
|
6
14
|
// reactUncontrolled
|
|
7
15
|
reactUncontrolled: (ko)=>({
|
|
@@ -59,8 +67,8 @@ function disposalCallback(el, ko) {
|
|
|
59
67
|
return ()=>ReactDOM.unmountComponentAtNode(el);
|
|
60
68
|
}
|
|
61
69
|
function initRoot(ko, el, allBindings) {
|
|
62
|
-
if (
|
|
63
|
-
const root =
|
|
70
|
+
if (createRoot && allBindings.get('legacyRoot') !== true) {
|
|
71
|
+
const root = createRoot(el);
|
|
64
72
|
ko.utils.domData.set(el, ROOT_KEY, root);
|
|
65
73
|
}
|
|
66
74
|
ko.utils.domNodeDisposal.addDisposeCallback(el, disposalCallback(el, ko));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ko-binding-handlers.tsx"],"sourcesContent":["import { ComponentType, Fragment, ReactElement, useEffect } from 'react';\nimport ReactDOM from 'react-dom';\nimport
|
|
1
|
+
{"version":3,"sources":["../src/ko-binding-handlers.tsx"],"sourcesContent":["import { ComponentType, Fragment, ReactElement, useEffect } from 'react';\nimport ReactDOM from 'react-dom';\nimport type ReactDOMClient from 'react-dom/client';\n\ntype KO = typeof import('knockout');\n\nlet createRoot: typeof ReactDOMClient.createRoot;\ntry {\n /**\n * Note, the webpack.IgnorePlugin must be configured to ignore this dependency.\n * @see {@link file://./../../startup/src/webpack/configs/plugins/ignore-plugin/ignore-plugin.ts}\n */\n createRoot = require('react-dom/client').createRoot;\n} catch {\n // ignore\n}\n\nexport const koBindingHandlers = {\n // reactUncontrolled\n reactUncontrolled: (ko: KO): KnockoutBindingHandler => ({\n init: (\n el: Element,\n valueAccessor: () => any,\n allBindings: KnockoutAllBindingsAccessor,\n _viewModel: any,\n bindingContext: KnockoutBindingContext\n ) => {\n initRoot(ko, el, allBindings);\n const Component = ko.unwrap<ComponentType>(valueAccessor());\n render(\n ko,\n el,\n <Fragment>\n <Component />\n <ApplyBindings bindingContext={bindingContext} el={el} ko={ko} />\n </Fragment>\n );\n return { controlsDescendantBindings: true };\n },\n }),\n // React component renderer for knockout\n react: (ko: KO): KnockoutBindingHandler => ({\n init: (\n el: Element,\n _valueAccessor: () => any,\n allBindings: KnockoutAllBindingsAccessor\n ) => {\n initRoot(ko, el, allBindings);\n return { controlsDescendantBindings: true }; // important\n },\n update: (\n el: Element,\n valueAccessor: () => any,\n allBindings: KnockoutAllBindingsAccessor,\n viewModel: any\n ) => {\n const Component = ko.unwrap<ComponentType>(valueAccessor());\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n const props = allBindings.get('props') || viewModel || null;\n render(ko, el, <Component {...props} />);\n },\n }),\n};\n\nfunction ApplyBindings({ bindingContext, el, ko }: { bindingContext: any; el: Element; ko: KO }) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(() => ko.applyBindingsToDescendants(bindingContext, el), []);\n return null;\n}\n\nconst ROOT_KEY = 'ko-binding-handler-root';\n\nfunction disposalCallback(el: Element, ko: KO) {\n const root = ko.utils.domData.get(el, ROOT_KEY);\n if (root) {\n return () => {\n root.unmount();\n ko.utils.domData.clear(el);\n };\n }\n // eslint-disable-next-line react/no-deprecated\n return () => ReactDOM.unmountComponentAtNode(el);\n}\nfunction initRoot(ko: KO, el: Element, allBindings: KnockoutAllBindingsAccessor) {\n if (createRoot && allBindings.get('legacyRoot') !== true) {\n const root = createRoot(el);\n ko.utils.domData.set(el, ROOT_KEY, root);\n }\n\n ko.utils.domNodeDisposal.addDisposeCallback(el, disposalCallback(el, ko));\n}\n\nfunction render(ko: KO, container: Element, element: ReactElement) {\n const root = ko.utils.domData.get(container, ROOT_KEY);\n if (root) {\n root.render(element);\n } else {\n // eslint-disable-next-line react/no-deprecated\n ReactDOM.render(element, container);\n }\n}\n"],"names":["Fragment","useEffect","ReactDOM","createRoot","require","koBindingHandlers","reactUncontrolled","ko","init","el","valueAccessor","allBindings","_viewModel","bindingContext","initRoot","Component","unwrap","render","ApplyBindings","controlsDescendantBindings","react","_valueAccessor","update","viewModel","props","get","applyBindingsToDescendants","ROOT_KEY","disposalCallback","root","utils","domData","unmount","clear","unmountComponentAtNode","set","domNodeDisposal","addDisposeCallback","container","element"],"mappings":";AAAA,SAAwBA,QAAQ,EAAgBC,SAAS,QAAQ,QAAQ;AACzE,OAAOC,cAAc,YAAY;AAKjC,IAAIC;AACJ,IAAI;IACA;;;KAGC,GACDA,aAAaC,QAAQ,oBAAoBD,UAAU;AACvD,EAAE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C,OAAO,IAAMP,SAASgC,sBAAsB,CAACzB;AACjD;AACA,SAASK,SAASP,EAAM,EAAEE,EAAW,EAAEE,WAAwC;IAC3E,IAAIR,cAAcQ,YAAYc,GAAG,CAAC,kBAAkB,MAAM;QACtD,MAAMI,OAAO1B,WAAWM;QACxBF,GAAGuB,KAAK,CAACC,OAAO,CAACI,GAAG,CAAC1B,IAAIkB,UAAUE;IACvC;IAEAtB,GAAGuB,KAAK,CAACM,eAAe,CAACC,kBAAkB,CAAC5B,IAAImB,iBAAiBnB,IAAIF;AACzE;AAEA,SAASU,OAAOV,EAAM,EAAE+B,SAAkB,EAAEC,OAAqB;IAC7D,MAAMV,OAAOtB,GAAGuB,KAAK,CAACC,OAAO,CAACN,GAAG,CAACa,WAAWX;IAC7C,IAAIE,MAAM;QACNA,KAAKZ,MAAM,CAACsB;IAChB,OAAO;QACH,+CAA+C;QAC/CrC,SAASe,MAAM,CAACsB,SAASD;IAC7B;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/ko-bridge",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "35.0.0",
|
|
4
4
|
"description": "Collection of components and utils to connect Knockout and React codebase",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/uikit/ko-bridge",
|
|
6
6
|
"repository": {
|
|
@@ -38,5 +38,6 @@
|
|
|
38
38
|
},
|
|
39
39
|
"cli": {
|
|
40
40
|
"webpack": false
|
|
41
|
-
}
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "3a5f2e6cad93c4e898091fb3d51310ccb26a91ee"
|
|
42
43
|
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { ComponentType, Fragment, ReactElement, useEffect } from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
|
-
import
|
|
3
|
+
import type ReactDOMClient from 'react-dom/client';
|
|
4
4
|
|
|
5
5
|
type KO = typeof import('knockout');
|
|
6
6
|
|
|
7
|
+
let createRoot: typeof ReactDOMClient.createRoot;
|
|
8
|
+
try {
|
|
9
|
+
/**
|
|
10
|
+
* Note, the webpack.IgnorePlugin must be configured to ignore this dependency.
|
|
11
|
+
* @see {@link file://./../../startup/src/webpack/configs/plugins/ignore-plugin/ignore-plugin.ts}
|
|
12
|
+
*/
|
|
13
|
+
createRoot = require('react-dom/client').createRoot;
|
|
14
|
+
} catch {
|
|
15
|
+
// ignore
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
export const koBindingHandlers = {
|
|
8
19
|
// reactUncontrolled
|
|
9
20
|
reactUncontrolled: (ko: KO): KnockoutBindingHandler => ({
|
|
@@ -71,8 +82,8 @@ function disposalCallback(el: Element, ko: KO) {
|
|
|
71
82
|
return () => ReactDOM.unmountComponentAtNode(el);
|
|
72
83
|
}
|
|
73
84
|
function initRoot(ko: KO, el: Element, allBindings: KnockoutAllBindingsAccessor) {
|
|
74
|
-
if (
|
|
75
|
-
const root =
|
|
85
|
+
if (createRoot && allBindings.get('legacyRoot') !== true) {
|
|
86
|
+
const root = createRoot(el);
|
|
76
87
|
ko.utils.domData.set(el, ROOT_KEY, root);
|
|
77
88
|
}
|
|
78
89
|
|