Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@tko/provider.component

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tko/provider.component - npm Package Compare versions

Comparing version
4.0.0-beta1.6
to
4.0.0
+27
-33
dist/ComponentProvider.js

@@ -0,27 +1,19 @@

// @tko/provider.component 🥊 4.0.0 ESM
"use strict";
// @tko/provider.component 🥊 4.0.0-beta1.6 ESM
import {
tagNameLower,
objectMap
} from "@tko/utils";
import { tagNameLower, objectMap } from "@tko/utils";
import registry from "@tko/utils.component";
import {
unwrap,
isWriteableObservable
} from "@tko/observable";
import {
computed
} from "@tko/computed";
import {
Provider
} from "@tko/provider";
import {
Parser
} from "@tko/utils.parser";
import { unwrap, isWriteableObservable } from "@tko/observable";
import { computed } from "@tko/computed";
import { Provider } from "@tko/provider";
import { Parser } from "@tko/utils.parser";
export default class ComponentProvider extends Provider {
get FOR_NODE_TYPES() {
return [1];
return [Node.ELEMENT_NODE];
}
/**
* Convert <slot name='X'> to <!-- ko slot: 'X' --><!-- /ko -->
* @param {Node} node
*/
preprocessNode(node) {
if (node.tagName === "SLOT") {
if (node instanceof Element && node.tagName === "SLOT") {
const parent = node.parentNode;

@@ -31,2 +23,5 @@ const slotName = node.getAttribute("name") || "";

const closeNode = document.createComment("/ko");
if (!parent) {
throw Error("Missing parent node");
}
parent.insertBefore(openNode, node);

@@ -37,2 +32,3 @@ parent.insertBefore(closeNode, node);

}
return null;
}

@@ -45,13 +41,10 @@ nodeHasBindings(node) {

if (!componentName) {
return;
return /* @__PURE__ */ Object.create(null);
}
const component = () => ({
name: componentName,
params: this.getComponentParams(node, context)
});
const component = () => ({ name: componentName, params: this.getComponentParams(node, context) });
return { component };
}
getComponentNameForNode(node) {
if (node.nodeType !== node.ELEMENT_NODE) {
return;
if (!(node instanceof Element) || node.nodeType !== Node.ELEMENT_NODE) {
return null;
}

@@ -66,14 +59,15 @@ const tagName = tagNameLower(node);

}
return null;
}
getComponentParams(node, context) {
if (!(node instanceof Element)) {
return { $raw: {} };
}
const parser = new Parser(node, context, this.globals);
const paramsString = (node.getAttribute("params") || "").trim();
const accessors = parser.parse(paramsString, context, node);
const accessors = parser.parse(paramsString, context, void 0, node);
if (!accessors || Object.keys(accessors).length === 0) {
return { $raw: {} };
}
const $raw = objectMap(
accessors,
(value) => computed(value, null, { disposeWhenNodeIsRemoved: node })
);
const $raw = objectMap(accessors, (value) => computed(value, null, { disposeWhenNodeIsRemoved: node }));
const params = objectMap($raw, (v) => this.makeParamValue(node, v));

@@ -90,3 +84,3 @@ return Object.assign({ $raw }, params);

read: () => unwrap(paramValueComputed()),
write: isWriteable ? (v) => paramValueComputed()(v) : null,
write: isWriteable ? (v) => paramValueComputed()(v) : void 0,
disposeWhenNodeIsRemoved: node

@@ -93,0 +87,0 @@ });

{
"version": 3,
"sources": ["../src/ComponentProvider.ts"],
"sourcesContent": ["\nimport {\n tagNameLower, objectMap\n} from '@tko/utils'\n\nimport registry from '@tko/utils.component'\n\nimport {\n unwrap, isWriteableObservable\n} from '@tko/observable'\n\nimport {\n computed\n} from '@tko/computed'\n\nimport {\n Provider\n} from '@tko/provider'\n\nimport {\n Parser\n} from '@tko/utils.parser'\n\nexport default class ComponentProvider extends Provider {\n get FOR_NODE_TYPES () { return [ 1 ] } // document.ELEMENT_NODE\n\n /**\n * Convert <slot name='X'> to <!-- ko slot: 'X' --><!-- /ko -->\n * @param {HTMLElement} node\n */\n preprocessNode (node) {\n if (node.tagName === 'SLOT') {\n const parent = node.parentNode\n const slotName = node.getAttribute('name') || ''\n const openNode = document.createComment(`ko slot: \"${slotName}\"`)\n const closeNode = document.createComment('/ko')\n parent.insertBefore(openNode, node)\n parent.insertBefore(closeNode, node)\n parent.removeChild(node)\n return [openNode, closeNode]\n }\n }\n\n nodeHasBindings (node) {\n return Boolean(this.getComponentNameForNode(node))\n }\n\n getBindingAccessors (node, context) {\n const componentName = this.getComponentNameForNode(node)\n if (!componentName) { return }\n const component = () => ({\n name: componentName,\n params: this.getComponentParams(node, context)\n })\n return { component }\n }\n\n getComponentNameForNode (node) {\n if (node.nodeType !== node.ELEMENT_NODE) { return }\n const tagName = tagNameLower(node)\n if (registry.isRegistered(tagName)) {\n const hasDash = tagName.includes('-')\n const isUnknownEntity = ('' + node) === '[object HTMLUnknownElement]'\n if (hasDash || isUnknownEntity) { return tagName }\n }\n }\n\n getComponentParams (node, context) {\n const parser = new Parser(node, context, this.globals)\n const paramsString = (node.getAttribute('params') || '').trim()\n const accessors = parser.parse(paramsString, context, node)\n if (!accessors || Object.keys(accessors).length === 0) {\n return { $raw: {} }\n }\n const $raw = objectMap(accessors,\n (value) => computed(value, null, { disposeWhenNodeIsRemoved: node })\n )\n const params = objectMap($raw, (v) => this.makeParamValue(node, v))\n return Object.assign({ $raw }, params)\n }\n\n makeParamValue (node, paramValueComputed) {\n const paramValue = paramValueComputed.peek()\n // Does the evaluation of the parameter value unwrap any observables?\n if (!paramValueComputed.isActive()) {\n // No it doesn't, so there's no need for any computed wrapper. Just pass through the supplied value directly.\n // Example: \"someVal: firstName, age: 123\" (whether or not firstName is an observable/computed)\n return paramValue\n }\n // Yes it does. Supply a computed property that unwraps both the outer (binding expression)\n // level of observability, and any inner (resulting model value) level of observability.\n // This means the component doesn't have to worry about multiple unwrapping. If the value is a\n // writable observable, the computed will also be writable and pass the value on to the observable.\n const isWriteable = isWriteableObservable(paramValue)\n\n return computed({\n read: () => unwrap(paramValueComputed()),\n write: isWriteable ? (v) => paramValueComputed()(v) : null,\n disposeWhenNodeIsRemoved: node\n })\n }\n}\n"],
"mappings": ";;AACA;AAAA,EACE;AAAA,EAAc;AAAA,OACT;AAEP,OAAO,cAAc;AAErB;AAAA,EACE;AAAA,EAAQ;AAAA,OACH;AAEP;AAAA,EACE;AAAA,OACK;AAEP;AAAA,EACE;AAAA,OACK;AAEP;AAAA,EACE;AAAA,OACK;AAEP,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,cAAc,SAAS,IAAI;AAC1D,QAAI,CAAC,aAAa,OAAO,KAAK,SAAS,EAAE,WAAW,GAAG;AACrD,aAAO,EAAE,MAAM,CAAC,EAAE;AAAA,IACpB;AACA,UAAM,OAAO;AAAA,MAAU;AAAA,MACrB,CAAC,UAAU,SAAS,OAAO,MAAM,EAAE,0BAA0B,KAAK,CAAC;AAAA,IACrE;AACA,UAAM,SAAS,UAAU,MAAM,CAAC,MAAM,KAAK,eAAe,MAAM,CAAC,CAAC;AAClE,WAAO,OAAO,OAAO,EAAE,KAAK,GAAG,MAAM;AAAA,EACvC;AAAA,EAEA,eAAgB,MAAM,oBAAoB;AACxC,UAAM,aAAa,mBAAmB,KAAK;AAE3C,QAAI,CAAC,mBAAmB,SAAS,GAAG;AAGlC,aAAO;AAAA,IACT;AAKA,UAAM,cAAc,sBAAsB,UAAU;AAEpD,WAAO,SAAS;AAAA,MACd,MAAM,MAAM,OAAO,mBAAmB,CAAC;AAAA,MACvC,OAAO,cAAc,CAAC,MAAM,mBAAmB,EAAE,CAAC,IAAI;AAAA,MACtD,0BAA0B;AAAA,IAC5B,CAAC;AAAA,EACH;AACF;",
"sourcesContent": ["import { tagNameLower, objectMap } from '@tko/utils'\n\nimport registry from '@tko/utils.component'\n\nimport { unwrap, isWriteableObservable } from '@tko/observable'\n\nimport { computed } from '@tko/computed'\n\nimport { Provider } from '@tko/provider'\n\nimport { Parser } from '@tko/utils.parser'\n\nexport default class ComponentProvider extends Provider {\n override get FOR_NODE_TYPES() {\n return [Node.ELEMENT_NODE]\n }\n\n /**\n * Convert <slot name='X'> to <!-- ko slot: 'X' --><!-- /ko -->\n * @param {Node} node\n */\n override preprocessNode(node: Node): Node[] | null {\n if (node instanceof Element && node.tagName === 'SLOT') {\n const parent = node.parentNode\n const slotName = node.getAttribute('name') || ''\n const openNode = document.createComment(`ko slot: \"${slotName}\"`)\n const closeNode = document.createComment('/ko')\n\n if (!parent) {\n throw Error('Missing parent node')\n }\n\n parent.insertBefore(openNode, node)\n parent.insertBefore(closeNode, node)\n parent.removeChild(node)\n\n return [openNode, closeNode]\n }\n return null\n }\n\n override nodeHasBindings(node: Node): boolean {\n return Boolean(this.getComponentNameForNode(node))\n }\n\n override getBindingAccessors(node: Node, context) {\n const componentName = this.getComponentNameForNode(node)\n if (!componentName) {\n return Object.create(null)\n }\n const component = () => ({ name: componentName, params: this.getComponentParams(node, context) })\n return { component }\n }\n\n getComponentNameForNode(node: Node): string | null {\n if (!(node instanceof Element) || node.nodeType !== Node.ELEMENT_NODE) {\n return null\n }\n const tagName = tagNameLower(node)\n if (registry.isRegistered(tagName)) {\n const hasDash = tagName.includes('-')\n const isUnknownEntity = '' + node === '[object HTMLUnknownElement]'\n if (hasDash || isUnknownEntity) {\n return tagName\n }\n }\n return null\n }\n\n getComponentParams(node: Node, context) {\n if (!(node instanceof Element)) {\n return { $raw: {} }\n }\n\n const parser = new (Parser as any)(node, context, this.globals) as Parser\n const paramsString = (node.getAttribute('params') || '').trim()\n const accessors = parser.parse(paramsString, context, undefined, node)\n if (!accessors || Object.keys(accessors).length === 0) {\n return { $raw: {} }\n }\n const $raw = objectMap(accessors, value => computed(value, null, { disposeWhenNodeIsRemoved: node }))\n const params = objectMap($raw, v => this.makeParamValue(node, v))\n return Object.assign({ $raw }, params)\n }\n\n makeParamValue(node: Element, paramValueComputed) {\n const paramValue = paramValueComputed.peek()\n // Does the evaluation of the parameter value unwrap any observables?\n if (!paramValueComputed.isActive()) {\n // No it doesn't, so there's no need for any computed wrapper. Just pass through the supplied value directly.\n // Example: \"someVal: firstName, age: 123\" (whether or not firstName is an observable/computed)\n return paramValue\n }\n // Yes it does. Supply a computed property that unwraps both the outer (binding expression)\n // level of observability, and any inner (resulting model value) level of observability.\n // This means the component doesn't have to worry about multiple unwrapping. If the value is a\n // writable observable, the computed will also be writable and pass the value on to the observable.\n const isWriteable = isWriteableObservable(paramValue)\n\n return computed({\n read: () => unwrap(paramValueComputed()),\n write: isWriteable ? v => paramValueComputed()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M
export { default as ComponentProvider } from "./ComponentProvider";
{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["export {default as ComponentProvider} from './ComponentProvider'\n"],
"mappings": ";;AAAA,6CAA2C;",
"sourcesContent": ["export { default as ComponentProvider } from './ComponentProvider'\n"],
"mappings": ";;AAAA,SAAS,WAAW,yBAAyB;",
"names": []
}

@@ -0,3 +1,3 @@

// @tko/provider.component 🥊 4.0.0 MJS
"use strict";
// @tko/provider.component 🥊 4.0.0-beta1.6 MJS
export { default as ComponentProvider } from "./ComponentProvider";
{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["export {default as ComponentProvider} from './ComponentProvider'\n"],
"mappings": ";;AAAA,6CAA2C;",
"sourcesContent": ["export { default as ComponentProvider } from './ComponentProvider'\n"],
"mappings": ";;AAAA,SAAS,WAAW,yBAAyB;",
"names": []
}
{
"version": "4.0.0-beta1.6",
"version": "4.0.0",
"name": "@tko/provider.component",

@@ -12,8 +12,8 @@ "description": "Bind custom web components e.g. <custom-binding>",

"dependencies": {
"@tko/computed": "^4.0.0-beta1.3",
"@tko/observable": "^4.0.0-beta1.3",
"@tko/provider": "^4.0.0-beta1.3",
"@tko/utils": "^4.0.0-beta1.3",
"@tko/utils.component": "^4.0.0-beta1.3",
"@tko/utils.parser": "^4.0.0-beta1.6",
"@tko/computed": "^4.0.0",
"@tko/observable": "^4.0.0",
"@tko/provider": "^4.0.0",
"@tko/utils": "^4.0.0",
"@tko/utils.component": "^4.0.0",
"@tko/utils.parser": "^4.0.0",
"tslib": "^2.2.0"

@@ -47,4 +47,3 @@ },

"url": "git+https://github.com/knockout/tko.git"
},
"gitHead": "c31dee2a2aa3f07e798d59e3aaf0da955dbcacb0"
}
}
The MIT License (MIT) - http://www.opensource.org/licenses/mit-license.php
Copyright (c) Steven Sanderson, the Knockout.js team, and other contributors
http://knockoutjs.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display