@servicetitan/ko-bridge 37.0.2 → 38.1.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/html-comment.js
CHANGED
package/dist/html-comment.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/html-comment.tsx"],"sourcesContent":["import { Component, createRef } from 'react';\n\nexport interface CommentProps {\n text: string;\n isInTable?: boolean;\n parent?: string;\n}\n\nexport class HtmlComment extends Component<CommentProps> {\n private parentNode: Node | null = null;\n private commentNode: Node | null = null;\n private spanNode: Node | null = null;\n private ref = createRef<HTMLElement>();\n\n componentDidMount() {\n this.spanNode = this.ref.current;\n this.parentNode = this.spanNode?.parentNode ?? null;\n\n if (this.parentNode && this.spanNode) {\n this.commentNode = document.createComment(this.props.text);\n this.parentNode.replaceChild(this.commentNode, this.spanNode);\n }\n }\n\n componentDidUpdate() {\n if (\n this.parentNode &&\n this.spanNode &&\n this.commentNode &&\n this.commentNode.textContent !== this.props.text\n ) {\n this.commentNode.textContent = this.props.text;\n }\n }\n\n componentWillUnmount() {\n if (\n this.parentNode &&\n this.spanNode &&\n this.commentNode &&\n this.parentNode.contains(this.commentNode)\n ) {\n this.parentNode.replaceChild(this.spanNode, this.commentNode);\n }\n }\n\n render() {\n const ElementType = getElementType(this.props);\n return <ElementType ref={this.ref as any} />;\n }\n}\n\nfunction getElementType(props: { isInTable?: boolean; parent?: string }) {\n const { isInTable, parent } = props;\n\n if (isInTable) {\n if (parent === 'tr') {\n return 'td';\n }\n\n return 'tr';\n }\n\n if (parent === 'select') {\n return 'option';\n }\n\n return 'span';\n}\n"],"names":["Component","createRef","HtmlComment","componentDidMount","spanNode","ref","current","parentNode","commentNode","document","createComment","props","text","replaceChild","componentDidUpdate","textContent","componentWillUnmount","contains","render","ElementType","getElementType","isInTable","parent"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/html-comment.tsx"],"sourcesContent":["import { Component, createRef } from 'react';\n\nexport interface CommentProps {\n text: string;\n isInTable?: boolean;\n parent?: string;\n}\n\nexport class HtmlComment extends Component<CommentProps> {\n private parentNode: Node | null = null;\n private commentNode: Node | null = null;\n private spanNode: Node | null = null;\n private ref = createRef<HTMLElement>();\n\n componentDidMount() {\n this.spanNode = this.ref.current;\n this.parentNode = this.spanNode?.parentNode ?? null;\n\n if (this.parentNode && this.spanNode) {\n this.commentNode = document.createComment(this.props.text);\n this.parentNode.replaceChild(this.commentNode, this.spanNode);\n }\n }\n\n componentDidUpdate() {\n if (\n this.parentNode &&\n this.spanNode &&\n this.commentNode &&\n this.commentNode.textContent !== this.props.text\n ) {\n this.commentNode.textContent = this.props.text;\n }\n }\n\n componentWillUnmount() {\n if (\n this.parentNode &&\n this.spanNode &&\n this.commentNode &&\n this.parentNode.contains(this.commentNode)\n ) {\n this.parentNode.replaceChild(this.spanNode, this.commentNode);\n }\n }\n\n render() {\n const ElementType = getElementType(this.props);\n return <ElementType ref={this.ref as any} />;\n }\n}\n\nfunction getElementType(props: { isInTable?: boolean; parent?: string }) {\n const { isInTable, parent } = props;\n\n if (isInTable) {\n if (parent === 'tr') {\n return 'td';\n }\n\n return 'tr';\n }\n\n if (parent === 'select') {\n return 'option';\n }\n\n return 'span';\n}\n"],"names":["Component","createRef","HtmlComment","componentDidMount","spanNode","ref","current","parentNode","commentNode","document","createComment","props","text","replaceChild","componentDidUpdate","textContent","componentWillUnmount","contains","render","ElementType","getElementType","isInTable","parent"],"mappings":";;;;;;;;;;;;AAAA,SAASA,SAAS,EAAEC,SAAS,QAAQ,QAAQ;AAQ7C,OAAO,MAAMC,oBAAoBF;IAM7BG,oBAAoB;;YAEE;QADlB,IAAI,CAACC,QAAQ,GAAG,IAAI,CAACC,GAAG,CAACC,OAAO;QAChC,IAAI,CAACC,UAAU,YAAG,iBAAA,IAAI,CAACH,QAAQ,cAAb,qCAAA,eAAeG,UAAU,uCAAI;QAE/C,IAAI,IAAI,CAACA,UAAU,IAAI,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["/* eslint-disable no-console */\nimport {\n Component,\n createRef,\n ForwardRefExoticComponent,\n PropsWithoutRef,\n RefAttributes,\n} from 'react';\n\ndeclare const ko: any;\n\nexport interface KnockoutComponentProps {\n koModel: any;\n koTemplate: KnockoutTemplate<any>;\n dangerouslyUpdatable?: boolean;\n}\n\ntype KnockoutTemplate<T extends HTMLElement, P = object> =\n // Got it from React.forwardRef declaration\n ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;\n\nexport class KnockoutComponent extends Component<KnockoutComponentProps> {\n static defaultProps: Partial<KnockoutComponentProps> = {\n dangerouslyUpdatable: false,\n };\n private isBindingApplied = false;\n private ref = createRef<HTMLElement>();\n private node: HTMLElement | null = null;\n private origVisibility?: string;\n componentDidMount() {\n this.initNode();\n this.initOrigVisibility();\n this.applyBinding();\n this.updateNodeVisibility();\n }\n shouldComponentUpdate(nextProps: KnockoutComponentProps) {\n if (this.props.koTemplate !== nextProps.koTemplate) {\n console.error(\"Knockout template can't be changed during component life cycle.\");\n return false;\n }\n if (this.isBindingApplied && this.props.koModel !== nextProps.koModel) {\n if (!this.props.dangerouslyUpdatable) {\n console.error(`\n Knockout model can\\'t be changed after it\\'s applied.\n If you really need it to be reapplied set dangerouslyUpdatable prop to true.\n Make sure that you know the risks.\n `);\n return false;\n }\n return true;\n }\n return !this.isBindingApplied && this.props.koModel !== nextProps.koModel;\n }\n getSnapshotBeforeUpdate() {\n this.cleanNode();\n return null;\n }\n componentDidUpdate() {\n this.applyBinding();\n this.updateNodeVisibility();\n }\n componentWillUnmount() {\n this.cleanNode();\n this.restoreOrigVisibility();\n }\n render() {\n const { koTemplate: KoTemplate } = this.props;\n\n return <KoTemplate ref={this.ref} />;\n }\n private isModelValid(koModel: any): boolean {\n return koModel !== undefined;\n }\n private initNode() {\n if (!(this.ref.current instanceof HTMLElement)) {\n console.error(\n 'Knockout template should forward `ref` to HTMLElement.' +\n 'See https://reactjs.org/docs/forwarding-refs.html for more details.\\n',\n this.props.koTemplate\n );\n return;\n }\n\n this.node = this.ref.current!;\n }\n private initOrigVisibility() {\n this.origVisibility = window.getComputedStyle(this.node!).visibility || 'visible';\n }\n private updateNodeVisibility() {\n const isValid = this.isModelValid(this.props.koModel);\n this.node!.style.visibility = isValid ? this.origVisibility! : 'hidden';\n }\n private restoreOrigVisibility() {\n this.node!.style.visibility = this.origVisibility!;\n this.origVisibility = undefined;\n }\n private cleanNode() {\n if (!this.isBindingApplied) {\n return;\n }\n ko.cleanNode(this.node!);\n this.isBindingApplied = false;\n }\n private applyBinding() {\n const koModel = Object.hasOwn(this.props, 'koModel') ? this.props.koModel : null;\n if (this.isModelValid(koModel)) {\n ko.applyBindings(koModel, this.node!);\n this.isBindingApplied = true;\n }\n }\n}\n"],"names":["Component","createRef","KnockoutComponent","componentDidMount","initNode","initOrigVisibility","applyBinding","updateNodeVisibility","shouldComponentUpdate","nextProps","props","koTemplate","console","error","isBindingApplied","koModel","dangerouslyUpdatable","getSnapshotBeforeUpdate","cleanNode","componentDidUpdate","componentWillUnmount","restoreOrigVisibility","render","KoTemplate","ref","isModelValid","undefined","current","HTMLElement","node","origVisibility","window","getComputedStyle","visibility","isValid","style","ko","Object","hasOwn","applyBindings","defaultProps"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/knockout-component.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport {\n Component,\n createRef,\n ForwardRefExoticComponent,\n PropsWithoutRef,\n RefAttributes,\n} from 'react';\n\ndeclare const ko: any;\n\nexport interface KnockoutComponentProps {\n koModel: any;\n koTemplate: KnockoutTemplate<any>;\n dangerouslyUpdatable?: boolean;\n}\n\ntype KnockoutTemplate<T extends HTMLElement, P = object> =\n // Got it from React.forwardRef declaration\n ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;\n\nexport class KnockoutComponent extends Component<KnockoutComponentProps> {\n static defaultProps: Partial<KnockoutComponentProps> = {\n dangerouslyUpdatable: false,\n };\n private isBindingApplied = false;\n private ref = createRef<HTMLElement>();\n private node: HTMLElement | null = null;\n private origVisibility?: string;\n componentDidMount() {\n this.initNode();\n this.initOrigVisibility();\n this.applyBinding();\n this.updateNodeVisibility();\n }\n shouldComponentUpdate(nextProps: KnockoutComponentProps) {\n if (this.props.koTemplate !== nextProps.koTemplate) {\n console.error(\"Knockout template can't be changed during component life cycle.\");\n return false;\n }\n if (this.isBindingApplied && this.props.koModel !== nextProps.koModel) {\n if (!this.props.dangerouslyUpdatable) {\n console.error(`\n Knockout model can\\'t be changed after it\\'s applied.\n If you really need it to be reapplied set dangerouslyUpdatable prop to true.\n Make sure that you know the risks.\n `);\n return false;\n }\n return true;\n }\n return !this.isBindingApplied && this.props.koModel !== nextProps.koModel;\n }\n getSnapshotBeforeUpdate() {\n this.cleanNode();\n return null;\n }\n componentDidUpdate() {\n this.applyBinding();\n this.updateNodeVisibility();\n }\n componentWillUnmount() {\n this.cleanNode();\n this.restoreOrigVisibility();\n }\n render() {\n const { koTemplate: KoTemplate } = this.props;\n\n return <KoTemplate ref={this.ref} />;\n }\n private isModelValid(koModel: any): boolean {\n return koModel !== undefined;\n }\n private initNode() {\n if (!(this.ref.current instanceof HTMLElement)) {\n console.error(\n 'Knockout template should forward `ref` to HTMLElement.' +\n 'See https://reactjs.org/docs/forwarding-refs.html for more details.\\n',\n this.props.koTemplate\n );\n return;\n }\n\n this.node = this.ref.current!;\n }\n private initOrigVisibility() {\n this.origVisibility = window.getComputedStyle(this.node!).visibility || 'visible';\n }\n private updateNodeVisibility() {\n const isValid = this.isModelValid(this.props.koModel);\n this.node!.style.visibility = isValid ? this.origVisibility! : 'hidden';\n }\n private restoreOrigVisibility() {\n this.node!.style.visibility = this.origVisibility!;\n this.origVisibility = undefined;\n }\n private cleanNode() {\n if (!this.isBindingApplied) {\n return;\n }\n ko.cleanNode(this.node!);\n this.isBindingApplied = false;\n }\n private applyBinding() {\n const koModel = Object.hasOwn(this.props, 'koModel') ? this.props.koModel : null;\n if (this.isModelValid(koModel)) {\n ko.applyBindings(koModel, this.node!);\n this.isBindingApplied = true;\n }\n }\n}\n"],"names":["Component","createRef","KnockoutComponent","componentDidMount","initNode","initOrigVisibility","applyBinding","updateNodeVisibility","shouldComponentUpdate","nextProps","props","koTemplate","console","error","isBindingApplied","koModel","dangerouslyUpdatable","getSnapshotBeforeUpdate","cleanNode","componentDidUpdate","componentWillUnmount","restoreOrigVisibility","render","KoTemplate","ref","isModelValid","undefined","current","HTMLElement","node","origVisibility","window","getComputedStyle","visibility","isValid","style","ko","Object","hasOwn","applyBindings","defaultProps"],"mappings":";;;;;;;;;;;;AAAA,6BAA6B,GAC7B,SACIA,SAAS,EACTC,SAAS,QAIN,QAAQ;AAcf,OAAO,MAAMC,0BAA0BF;IAQnCG,oBAAoB;QAChB,IAAI,CAACC,QAAQ;QACb,IAAI,CAACC,kBAAkB;QACvB,IAAI,CAACC,YAAY;QACjB,IAAI,CAACC,oBAAoB;IAC7B;IACAC,sBAAsBC,SAAiC,EAAE;QACrD,IAAI,IAAI,CAACC,KAAK,CAACC,UAAU,KAAKF,UAAUE,UAAU,EAAE;YAChDC,QAAQC,KAAK,CAAC;YACd,OAAO;QACX;QACA,IAAI,IAAI,CAACC,gBAAgB,IAAI,IAAI,CAACJ,KAAK,CAACK,OAAO,KAAKN,UAAUM,OAAO,EAAE;YACnE,IAAI,CAAC,IAAI,CAACL,KAAK,CAACM,oBAAoB,EAAE;gBAClCJ,QAAQC,KAAK,CAAC,CAAC;;;;gBAIf,CAAC;gBACD,OAAO;YACX;YACA,OAAO;QACX;QACA,OAAO,CAAC,IAAI,CAACC,gBAAgB,IAAI,IAAI,CAACJ,KAAK,CAACK,OAAO,KAAKN,UAAUM,OAAO;IAC7E;IACAE,0BAA0B;QACtB,IAAI,CAACC,SAAS;QACd,OAAO;IACX;IACAC,qBAAqB;QACjB,IAAI,CAACb,YAAY;QACjB,IAAI,CAACC,oBAAoB;IAC7B;IACAa,uBAAuB;QACnB,IAAI,CAACF,SAAS;QACd,IAAI,CAACG,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AACc,IAAI;YACnC,IAAI,CAACf,gBAAgB,GAAG;QAC5B;IACJ;;QAxFG,gBAIH,uBAAQA,oBAAmB,QAC3B,uBAAQU,qBAAMvB,cACd,uBAAQ4B,QAA2B,OACnC,uBAAQC,kBAAR,KAAA;;AAkFJ;AAxFI,iBADS5B,mBACFsC,gBAAgD;IACnDxB,sBAAsB;AAC1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/ko-bridge",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "38.1.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": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"cli": {
|
|
40
40
|
"webpack": false
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "e8c601a26ad49ca0d6b0b84a9f530f3242d53c7f"
|
|
43
43
|
}
|