pawa-ssr 1.3.29 → 1.4.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/index.js CHANGED
@@ -484,12 +484,13 @@ appContext.component._prop={children,...el._props,...slots}
484
484
  }else{
485
485
  Object.assign(restProps,el._restProps)
486
486
  }
487
- const getAsChild=()=>{
488
- const asChild=div.firstElementChild
489
- if (splitAndAdd(asChild?.tagName|| '') === 'ASCHILD') {
490
- const getChildren=asChild.firstElementChild
487
+ const getAsChild=(divs)=>{
488
+ const divFirst=divs.firstElementChild
489
+ if (el._aschild) {
490
+ divs.innerHTML=children
491
+ const getChildren=divs.firstElementChild
491
492
  if (getChildren === null) return
492
- Array.from(asChild.attributes).forEach(attr=>{
493
+ Array.from(divFirst.attributes).forEach(attr=>{
493
494
  if (getChildren.hasAttribute(attr.name)) {
494
495
  let attrName=getChildren.getAttribute(attr.name)
495
496
  attrName=attr.value +' '+attrName
@@ -497,12 +498,10 @@ appContext.component._prop={children,...el._props,...slots}
497
498
  }else{
498
499
  getChildren.setAttribute(attr.name, attr.value)
499
500
  }
500
- })
501
- asChild.remove()
502
- div.appendChild(getChildren)
501
+ })
503
502
  }
504
- }
505
- getAsChild()
503
+ }
504
+ getAsChild(div)
506
505
  const findElement=div.querySelector('[--]') || div.querySelector('[r-]')
507
506
  if (findElement) {
508
507
  for (const [key,value] of Object.entries(restProps)) {
@@ -716,11 +715,12 @@ appContext.component._prop={children,...el._props,...slots}
716
715
  Object.assign(restProps,el._restProps)
717
716
  }
718
717
  const getAsChild=(divs)=>{
719
- const asChild=divs.firstElementChild
720
- if (splitAndAdd(asChild?.tagName|| '') === 'ASCHILD') {
721
- const getChildren=asChild.firstElementChild
718
+ const divFirst=divs.firstElementChild
719
+ if (el._aschild) {
720
+ divs.innerHTML=children
721
+ const getChildren=divs.firstElementChild
722
722
  if (getChildren === null) return
723
- Array.from(asChild.attributes).forEach(attr=>{
723
+ Array.from(divFirst.attributes).forEach(attr=>{
724
724
  if (getChildren.hasAttribute(attr.name)) {
725
725
  let attrName=getChildren.getAttribute(attr.name)
726
726
  attrName=attr.value +' '+attrName
@@ -728,9 +728,7 @@ appContext.component._prop={children,...el._props,...slots}
728
728
  }else{
729
729
  getChildren.setAttribute(attr.name, attr.value)
730
730
  }
731
- })
732
- asChild.remove()
733
- divs.appendChild(getChildren)
731
+ })
734
732
  }
735
733
  }
736
734
  if (isBoundary) {
@@ -931,7 +929,11 @@ const attributeHandler =async (el, attr) => {
931
929
  if (el._componentName) {
932
930
  return
933
931
  }
934
- el._replaceResumeAttr(attr.name,`c-at-${attr.name}`,attr.value)
932
+
933
+ const isAtAttr = attr.name.startsWith('@');
934
+ const targetName = isAtAttr ? attr.name.slice(1) : attr.name;
935
+
936
+ el._replaceResumeAttr(attr.name, `c-at-${targetName}`, attr.value);
935
937
  const currentHtmlString = el.outerHTML;
936
938
  const removableAttributes = new Set();
937
939
  removableAttributes.add('disabled');
@@ -945,18 +947,18 @@ const attributeHandler =async (el, attr) => {
945
947
  const func =el._evaluateExpr(
946
948
  expression,
947
949
  el._context,
948
- `from text interpolation @{} - ${expression} at ${currentHtmlString} attribute ${attr.name}`
950
+ `from text interpolation @{} - ${expression} at ${currentHtmlString} attribute ${targetName}`
949
951
  );
950
952
  value = value.replace(fullMatch, String(func));
951
953
  });
952
- if (removableAttributes.has(attr.name)) {
954
+ if (removableAttributes.has(targetName)) {
953
955
  if (value) {
954
- el.setAttribute(attr.name, '');
956
+ el.setAttribute(targetName, '');
955
957
  } else {
956
- el.removeAttribute(attr.name);
958
+ el.removeAttribute(targetName);
957
959
  }
958
960
  } else {
959
- el.setAttribute(attr.name, value);
961
+ el.setAttribute(targetName, value);
960
962
  }
961
963
  } catch (error) {
962
964
  console.log(error.message, error.stack);
@@ -1072,12 +1074,12 @@ export const render =async (el, contexts = {},stream) => {
1072
1074
  for(const attr of attributes){
1073
1075
  if (directives[attr.name]) {
1074
1076
  await directives[attr.name](el,attr,stream)
1075
- }else if(attr.value.includes('@{') && !isAcomponent){
1077
+ }else if((attr.value.includes('@{') || attr.name.startsWith('@')) && !isAcomponent){
1076
1078
  await attributeHandler(el,attr)
1077
1079
  }else if (attr.name.startsWith('state-')) {
1078
1080
  directives['state-'](el,attr)
1079
1081
  }
1080
- else if(fullNamePlugin.has(attr.name)) {
1082
+ else if(fullNamePlugin.has(attr.name) && !el._componentName) {
1081
1083
  if(externalPlugin[attr.name]){
1082
1084
  const plugin= externalPlugin[attr.name]
1083
1085
  try{
@@ -1090,9 +1092,9 @@ export const render =async (el, contexts = {},stream) => {
1090
1092
  console.warn(error.message,error.stack)
1091
1093
  }
1092
1094
  }
1093
- }else if(startAttribute){
1095
+ }else if(startAttribute ){
1094
1096
  const name=startObject[attr.name]
1095
- if(externalPlugin[name]){
1097
+ if(externalPlugin[name] && !el._componentName){
1096
1098
  const plugin= externalPlugin[name]
1097
1099
  try{
1098
1100
  if (typeof plugin !== 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawa-ssr",
3
- "version": "1.3.29",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "description": "pawajs ssr libary",
6
6
  "main": "index.js",
@@ -25,6 +25,6 @@
25
25
  "homepage": "https://github.com/Allisboy/pawajs-ssr#readme",
26
26
  "dependencies": {
27
27
  "linkedom": "^0.18.11",
28
- "pawajs": "^1.5.1"
28
+ "pawajs": "^2.0.0"
29
29
  }
30
30
  }
package/pawaElement.js CHANGED
@@ -19,6 +19,7 @@ class PawaElement {
19
19
  * @type{PawaElement|HTMLElement}
20
20
  */
21
21
  this._el=element
22
+ this._aschild=false
22
23
  this._slots=document.createDocumentFragment()
23
24
  this._context=context
24
25
  this._avoidPawaRender=element.hasAttribute('s-pawa-avoid')
@@ -166,6 +167,7 @@ class PawaElement {
166
167
 
167
168
  getComponent(){
168
169
  if (components.has(splitAndAdd(this._el.tagName.toUpperCase())) && !this._client || this._lazy) {
170
+ if(this._el.hasAttribute('data-prevent:c'))return
169
171
  this._componentName=splitAndAdd(this._el.tagName.toUpperCase())
170
172
  const fakeCompo=()=>true
171
173
  this._component=new PawaComponent(components.get(splitAndAdd(this._el.tagName.toUpperCase())),fakeCompo)
@@ -194,12 +196,13 @@ class PawaElement {
194
196
  //set Component props
195
197
  setProps(){
196
198
  if (this._componentName) {
197
- const allServerAttr=getPawaAttributes()
199
+ const allServerAttr=['if','else','else-if','key','for-each','case','switch','s-default']
198
200
  this._el.attributes.forEach(attr=>{
199
- if(!allServerAttr.has(attr.name)){
200
- if (attr.name === 'svg') {
201
- return
202
- }
201
+ if (attr.name ==='aschild' || attr.name === 'as-child' || attr.name === ':as-child') {
202
+ this._aschild=true
203
+ return
204
+ }
205
+ if(!allServerAttr.includes(attr.name)){
203
206
  if ( !attr.name.startsWith(':')) {
204
207
  if( attr.name.startsWith('c-')||attr.name.startsWith('pawa-') || attr.name.startsWith('p:c') || attr.name.startsWith('state-')) return
205
208
  let name=''
@@ -228,7 +231,7 @@ class PawaElement {
228
231
 
229
232
  });
230
233
  return value
231
- }else if( attr.name.startsWith('on-') || attr.name.startsWith('out-') || attr.name === 'ref'){
234
+ }else if( attr.name.startsWith('on-') || attr.name.startsWith('out-')){
232
235
  const res=this.evaluateExpr(`(e)=>{
233
236
  ${attr.value}
234
237
  }`, this._context,`evaluating props with template operators at ${attr.name} - ${attr.value} : ${this._template}`)
package/power.js CHANGED
@@ -316,8 +316,7 @@ export const For=async(el,attr,stream)=>{
316
316
  stream(`<!--${endComment.data}-->`)
317
317
  }else{
318
318
  template.setAttribute('pawa-render',true)
319
- stream(`<template pawa-render="true">${el.outerHTML}</template>`)
320
- template.appendChild(el)
319
+ stream(template.outerHTML)
321
320
  comment.replaceWith(template)
322
321
  endComment.remove()
323
322
  }
package/test/index.js CHANGED
@@ -1,17 +1,31 @@
1
- import {useValidateComponent, RegisterComponent,useContext,useInsert,setContext} from 'pawajs'
1
+ import {useValidateComponent, RegisterComponent,useContext,useInsert,setContext,forwardProps} from 'pawajs'
2
2
  import {startApp} from '../index.js'
3
3
  RegisterComponent.lazy(
4
4
  'App',()=>import('./App.js'),
5
5
  'Check',()=>import('./check.js'),
6
6
  'Check2',()=>import('./check.js'),
7
7
  )
8
-
8
+ const Dinput=({className,...props})=>{
9
+ forwardProps(props)
10
+ const classActive=()=>[className?.() || '','py-2 text-blue'].join(' ')
11
+ useInsert({classActive})
12
+ return `
13
+ <input class="@{classActive()}" -- />
14
+ `
15
+ }
16
+ RegisterComponent(Dinput)
9
17
  const app=`
10
18
  <div>
19
+ <dinput type="file" aschild>
20
+ <div>input</div>
21
+ </dinput>
11
22
  <app>
12
23
  <check></check>
13
24
  <check-2></check-2>
14
25
  </app>
26
+ <div state-array="['astro']">
27
+ <span for-each="item,i in array.value" for-key="{{item}}">@{item}</span>
28
+ </div>
15
29
  </div>
16
30
  `
17
31
  const {toString}=await startApp(app)