@webority/canvas-kit 0.120.1 → 0.121.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/ids.js +1 -1
- package/package.json +1 -1
package/dist/ids.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{basename as e,
|
|
1
|
+
import{basename as e,dirname as t,extname as n,join as r,relative as i,sep as a}from"node:path";import o from"@babel/parser";import{readFile as s,readdir as c,writeFile as l}from"node:fs/promises";var u=new Set([`node_modules`,`dist`,`build`]),d=new Set([`.jsx`,`.tsx`,`.js`]),f=[`react-native`,`@webority/mobile-ui`],p=new Set([`@webority/ui-react`,`@webority/mobile-ui`]),m=new Set([`section`,`form`,`header`,`nav`,`main`,`aside`,`article`,`fieldset`]),h=[`aria-label`,`name`,`id`,`title`,`label`,`placeholder`],g=new Set([`ArrowFunctionExpression`,`FunctionExpression`,`FunctionDeclaration`,`ObjectMethod`,`ClassMethod`]),_=new Set([`loc`,`start`,`end`,`comments`,`leadingComments`,`trailingComments`,`innerComments`,`tokens`,`extra`,`errors`]),v=40,y=new Set([`Fragment`,`React.Fragment`]);async function b(e,{write:t=!1}={}){let n=[],r=[],o=[],c=new Map;for(let t of await C(e)){let l=i(e,t).split(a).join(`/`),u=await s(t,`utf8`),d=w({source:u,file:t,label:l,phone:await x(t,c)});n.push(...d.proposals),r.push(...d.noKey),d.insertions.length>0&&o.push({file:t,source:u,insertions:d.insertions})}let u=0;if(t)for(let e of o){let t=e.source;for(let n of[...e.insertions].sort((e,t)=>t.offset-e.offset))t=`${t.slice(0,n.offset)}${n.text}${t.slice(n.offset)}`;await l(e.file,t,`utf8`),u+=e.insertions.length}return{proposals:n,noKey:r,written:u}}async function x(e,n){let i=[],a=t(e),o;for(;;){if(n.has(a)){o=n.get(a);break}i.push(a);let s=await S(r(a,`package.json`));if(s!==null){o=f.some(e=>s.dependencies?.[e]||s.peerDependencies?.[e]);break}let c=t(a);if(c===a)throw Error(`no package.json above ${e}`);a=c}for(let e of i)n.set(e,o);return o}async function S(e){try{return JSON.parse(await s(e,`utf8`))}catch(e){if(e.code===`ENOENT`)return null;throw e}}async function C(e){let t=await c(e,{withFileTypes:!0});t.sort((e,t)=>e.name<t.name?-1:1);let i=[];for(let a of t){let t=r(e,a.name);a.isDirectory()?u.has(a.name)||i.push(...await C(t)):a.isFile()&&d.has(n(a.name))&&!a.name.includes(`.test.`)&&i.push(t)}return i}function w({source:e,file:t,label:n,phone:r}){let i;try{i=o.parse(e,{sourceType:`module`,plugins:[`jsx`,`typescript`]})}catch(e){throw Error(`${n}: ${e.message}`)}let a=new Set;for(let e of i.program.body){if(e.type!==`ImportDeclaration`)continue;let t=e.source.value;if(p.has(t))for(let t of e.specifiers)t.type===`ImportSpecifier`&&a.add(t.local.name)}let s=r?`testID`:`data-canvas`,c=new Map,l=[];T(i.program,null,c,l);let u=L(t),d=t=>e.slice(t.start,t.end),f=new Map,m=[],h=[];for(let e of l){let t=e.openingElement,r=P(t,s),i=j(t,a),o=E(e,c);if(i!==null&&o===null&&A(f,e,i,r,c),!r)if(o!==null){let r=t.attributes.find(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===`key`)?.value,i=r?.type===`JSXExpressionContainer`?r.expression:null,a=o.params[1]?.type===`Identifier`?o.params[1].name:null,c=y.has(d(t.name))?D(e,d):e;c===null||i===null||i.type===`JSXEmptyExpression`||V(i)||i.type===`Identifier`&&i.name===a?h.push({start:e.start,entry:{file:n,line:e.loc.start.line,element:d(t.name)}}):(c===e||!P(c.openingElement,s))&&m.push({element:c,kind:`list`,keyExpression:i})}else i===null&&M(t)&&m.push({element:e,kind:`block`})}for(let e of f.values())for(let t of e.values())if(t.length>1&&t.some(e=>e.conditional))for(let e of t)e.skipped||m.push({element:e.element,kind:`sibling`});m.sort((e,t)=>e.element.start-t.element.start);let g=new Set,_=[],v=[];for(let e of m){let{element:t,kind:r}=e,i=t.openingElement,o=d(i.name),c=j(i,a),l=`${u}.${I(t,c===null?o:R(c))}`,f=r===`list`?`${l}.\${${d(e.keyExpression)}}`:l,p=f;if(g.has(p)){let e=2;for(;g.has(`${f}-${e}`);)e+=1;p=`${f}-${e}`}g.add(p);let m=r===`list`?` ${s}={\`${p}\`}`:` ${s}="${p}"`;_.push({file:n,line:t.loc.start.line,element:o,key:p}),v.push({offset:i.name.end,text:m})}return{proposals:_,noKey:h.sort((e,t)=>e.start-t.start).map(e=>e.entry),insertions:v}}function T(e,t,n,r){t!==null&&n.set(e,t),e.type===`JSXElement`&&r.push(e);for(let t of Object.keys(e)){if(_.has(t))continue;let i=e[t];for(let t of Array.isArray(i)?i:[i])typeof t==`object`&&t&&typeof t.type==`string`&&T(t,e,n,r)}}function E(e,t){let n=t.get(e),r=null;if(n?.type===`ArrowFunctionExpression`&&n.body===e)r=n;else if(n?.type===`ReturnStatement`){let e=t.get(n),i=t.get(e);e?.type===`BlockStatement`&&g.has(i?.type)&&i.body===e&&(r=i)}if(r===null)return null;let i=t.get(r);return i?.type===`CallExpression`&&i.arguments[0]===r&&i.callee.type===`MemberExpression`&&!i.callee.computed&&i.callee.property.type===`Identifier`&&i.callee.property.name===`map`?r:null}function D(e,t){for(let n of e.children)if(n.type===`JSXFragment`||n.type===`JSXElement`&&y.has(t(n.openingElement.name))){let e=D(n,t);if(e!==null)return e}else if(n.type===`JSXElement`)return n;return null}function O(e,t){for(let n=t.get(e);n!==void 0;n=t.get(n)){if(n.type===`JSXElement`||n.type===`JSXFragment`)return n;if(g.has(n.type))return null}return null}function k(e,t,n){for(let r=n.get(e);r!==t;r=n.get(r))if(r.type===`ConditionalExpression`||r.type===`LogicalExpression`&&r.operator===`&&`)return!0;return!1}function A(e,t,n,r,i){let a=O(t,i);if(a===null)return;e.has(a)||e.set(a,new Map);let o=e.get(a);o.has(n)||o.set(n,[]),o.get(n).push({element:t,skipped:r,conditional:k(t,a,i)})}function j(e,t){return e.name.type===`JSXIdentifier`&&t.has(e.name.name)?e.name.name:null}function M(e){if(e.name.type!==`JSXIdentifier`)return!1;let t=e.name.name;return m.has(t)||t===`div`&&(N(e,`id`)||N(e,`aria-label`))}function N(e,t){return e.attributes.some(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===t)}function P(e,t){return e.attributes.some(e=>e.type===`JSXSpreadAttribute`)||N(e,t)}function F(e,t){let n=e.attributes.find(e=>e.type===`JSXAttribute`&&e.name.type===`JSXIdentifier`&&e.name.name===t)?.value;if(n){if(n.type===`StringLiteral`)return n.value;if(n.type===`JSXExpressionContainer`){let e=n.expression;if(e.type===`StringLiteral`)return e.value;if(e.type===`TemplateLiteral`&&e.expressions.length===0)return e.quasis[0].value.cooked??void 0}}}function I(e,t){for(let t of h){let n=F(e.openingElement,t),r=n===void 0?``:B(z(n));if(r!==``)return r}let n=e.children.filter(e=>e.type===`JSXText`&&e.value.trim()!==``);if(n.length===1){let e=B(z(n[0].value));if(e!==``)return e}return B(z(t))}function L(t){return z(e(t,n(t))).replace(/-(screen|page)$/,``)}function R(e){return e.replace(/^App(?=[A-Z])/,``)}function z(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function B(e){if(e.length<=v)return e;let t=e.slice(0,41).lastIndexOf(`-`);return t>0?e.slice(0,t):e.slice(0,v)}function V(e){return e.type===`TemplateLiteral`?e.expressions.length===0:/Literal$/.test(e.type)}export{b as proposeCanvasKeys};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/canvas-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.121.0",
|
|
4
4
|
"description": "Builds product kits for Webority Canvas: a kit bundle, its manifest, and the spec shape the renderers answer.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"private": false,
|