@servicetitan/ko-bridge 36.4.0 → 37.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;AAEpC,eAAO,MAAM,iBAAiB;4BAEF,EAAE,KAAG,sBAAsB;gBAsBvC,EAAE,KAAG,sBAAsB;CAqB1C,CAAC"}
|
|
@@ -1,15 +1,7 @@
|
|
|
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
|
-
|
|
5
|
-
try {
|
|
6
|
-
/**
|
|
7
|
-
* Note, bundlers must be configured to ignore this dependency.
|
|
8
|
-
* @see {@link file://./../../startup/src/core/check-resource/is-managed-react-dom-client-dependency.ts}
|
|
9
|
-
*/ createRoot = require('react-dom/client').createRoot;
|
|
10
|
-
} catch (unused) {
|
|
11
|
-
// ignore
|
|
12
|
-
}
|
|
4
|
+
import * as ReactDOMClient from 'react-dom/client';
|
|
13
5
|
export const koBindingHandlers = {
|
|
14
6
|
// reactUncontrolled
|
|
15
7
|
reactUncontrolled: (ko)=>({
|
|
@@ -67,8 +59,8 @@ function disposalCallback(el, ko) {
|
|
|
67
59
|
return ()=>ReactDOM.unmountComponentAtNode(el);
|
|
68
60
|
}
|
|
69
61
|
function initRoot(ko, el, allBindings) {
|
|
70
|
-
if (createRoot && allBindings.get('legacyRoot') !== true) {
|
|
71
|
-
const root = createRoot(el);
|
|
62
|
+
if (ReactDOMClient.createRoot && allBindings.get('legacyRoot') !== true) {
|
|
63
|
+
const root = ReactDOMClient.createRoot(el);
|
|
72
64
|
ko.utils.domData.set(el, ROOT_KEY, root);
|
|
73
65
|
}
|
|
74
66
|
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 * as ReactDOMClient from 'react-dom/client';\n\ntype KO = typeof import('knockout');\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 (ReactDOMClient.createRoot && allBindings.get('legacyRoot') !== true) {\n const root = ReactDOMClient.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","ReactDOMClient","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","createRoot","set","domNodeDisposal","addDisposeCallback","container","element"],"mappings":";AAAA,SAAwBA,QAAQ,EAAgBC,SAAS,QAAQ,QAAQ;AACzE,OAAOC,cAAc,YAAY;AACjC,YAAYC,oBAAoB,mBAAmB;AAInD,OAAO,MAAMC,oBAAoB;IAC7B,oBAAoB;IACpBC,mBAAmB,CAACC,KAAoC,CAAA;YACpDC,MAAM,CACFC,IACAC,eACAC,aACAC,YACAC;gBAEAC,SAASP,IAAIE,IAAIE;gBACjB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,OAAOzB,eAAe+B,UAAU,CAAC1B;QACvCF,GAAGuB,KAAK,CAACC,OAAO,CAACK,GAAG,CAAC3B,IAAIkB,UAAUE;IACvC;IAEAtB,GAAGuB,KAAK,CAACO,eAAe,CAACC,kBAAkB,CAAC7B,IAAImB,iBAAiBnB,IAAIF;AACzE;AAEA,SAASU,OAAOV,EAAM,EAAEgC,SAAkB,EAAEC,OAAqB;IAC7D,MAAMX,OAAOtB,GAAGuB,KAAK,CAACC,OAAO,CAACN,GAAG,CAACc,WAAWZ;IAC7C,IAAIE,MAAM;QACNA,KAAKZ,MAAM,CAACuB;IAChB,OAAO;QACH,+CAA+C;QAC/CrC,SAASc,MAAM,CAACuB,SAASD;IAC7B;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/ko-bridge",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "37.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": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@types/react": "~18.3.3",
|
|
24
24
|
"@types/react-dom": "~18.3.0",
|
|
25
25
|
"knockout": "~3.0.0",
|
|
26
|
-
"mobx": "~6.
|
|
26
|
+
"mobx": "~6.16.1",
|
|
27
27
|
"react": "~18.3.1",
|
|
28
28
|
"react-dom": "~18.3.1"
|
|
29
29
|
},
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"cli": {
|
|
40
40
|
"webpack": false
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "f0acf332ece207c91acb18da23a614efbc8551ec"
|
|
43
43
|
}
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import { ComponentType, Fragment, ReactElement, useEffect } from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
|
-
import
|
|
3
|
+
import * as 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, bundlers must be configured to ignore this dependency.
|
|
11
|
-
* @see {@link file://./../../startup/src/core/check-resource/is-managed-react-dom-client-dependency.ts}
|
|
12
|
-
*/
|
|
13
|
-
createRoot = require('react-dom/client').createRoot;
|
|
14
|
-
} catch {
|
|
15
|
-
// ignore
|
|
16
|
-
}
|
|
17
|
-
|
|
18
7
|
export const koBindingHandlers = {
|
|
19
8
|
// reactUncontrolled
|
|
20
9
|
reactUncontrolled: (ko: KO): KnockoutBindingHandler => ({
|
|
@@ -82,8 +71,8 @@ function disposalCallback(el: Element, ko: KO) {
|
|
|
82
71
|
return () => ReactDOM.unmountComponentAtNode(el);
|
|
83
72
|
}
|
|
84
73
|
function initRoot(ko: KO, el: Element, allBindings: KnockoutAllBindingsAccessor) {
|
|
85
|
-
if (createRoot && allBindings.get('legacyRoot') !== true) {
|
|
86
|
-
const root = createRoot(el);
|
|
74
|
+
if (ReactDOMClient.createRoot && allBindings.get('legacyRoot') !== true) {
|
|
75
|
+
const root = ReactDOMClient.createRoot(el);
|
|
87
76
|
ko.utils.domData.set(el, ROOT_KEY, root);
|
|
88
77
|
}
|
|
89
78
|
|