pawa-ssr 1.3.8 → 1.3.9

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.
Files changed (3) hide show
  1. package/index.js +1 -1
  2. package/package.json +1 -1
  3. package/power.js +70 -89
package/index.js CHANGED
@@ -889,7 +889,7 @@ const attributeHandler =async (el, attr) => {
889
889
  partlyPawajsDirective.add(v)
890
890
  })
891
891
  }
892
- addToPartlyDirective('else','else-if','case')
892
+ addToPartlyDirective('else','else-if','case','default')
893
893
  const checkIfRemove=(el)=>{
894
894
  for (const v of partlyPawajsDirective) {
895
895
  if(el.hasAttribute(v)) return true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawa-ssr",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "type":"module",
5
5
  "description": "pawajs ssr libary",
6
6
  "main": "index.js",
package/power.js CHANGED
@@ -13,31 +13,28 @@ export const If = async(el, attr,stream) => {
13
13
  }]
14
14
  const chainMap=new Map()
15
15
  chainMap.set(el.getAttribute('if'),{condition:'if',element:el})
16
- const getChained=(nextSibling)=>{
17
- if (nextSibling !== null) {
18
- if (nextSibling && nextSibling.getAttribute('else') === '' || nextSibling.getAttribute('else-if')) {
19
- if (nextSibling.getAttribute('else-if')) {
20
- nextSibling.remove()
21
- chained.push({
22
- exp:nextSibling.getAttribute('else-if'),
23
- condition:'else-if',
24
- element:nextSibling
25
- })
26
- chainMap.set(nextSibling.getAttribute('else-if'),{condition:'else-if',element:nextSibling})
27
- getChained(nextSibling.nextElementSibling)
28
- }else if (nextSibling.getAttribute('else') === '') {
29
- chained.push({
30
- exp:'false',
31
- condition:'else',
32
- element:nextSibling
33
- })
34
- chainMap.set('else',{condition:'else',element:nextSibling})
35
- nextSibling.remove()
36
- }
37
- }
38
- }
39
- }
40
- getChained(nextSiblings)
16
+ const getChained = (sibling) => {
17
+ while (sibling) {
18
+ const next = sibling.nextElementSibling;
19
+ const isElseIf = sibling.hasAttribute('else-if');
20
+ const isElse = sibling.hasAttribute('else');
21
+
22
+ if (isElseIf) {
23
+ const exp = sibling.getAttribute('else-if');
24
+ chained.push({ exp, condition: 'else-if', element: sibling });
25
+ chainMap.set(exp, { condition: 'else-if', element: sibling });
26
+ sibling.remove();
27
+ } else if (isElse) {
28
+ chained.push({ exp: 'false', condition: 'else', element: sibling });
29
+ chainMap.set('else', { condition: 'else', element: sibling });
30
+ sibling.remove();
31
+ } else {
32
+ break;
33
+ }
34
+ sibling = next;
35
+ }
36
+ }
37
+ getChained(nextSiblings)
41
38
  let func=new Map()
42
39
  let current
43
40
  let latestChain
@@ -66,24 +63,17 @@ let latestChain
66
63
  let stringHtml=''
67
64
  const template=document.createElement('template')
68
65
  const store=document.createElement('template')
69
- chained.forEach((item,index) =>{
70
- const clone=item.element.cloneNode(true)
71
- clone._avoidPawaRender = true
72
- if (index === 0) {
73
- Array.from(clone.attributes).forEach(at => {
74
- if (at.name.startsWith('c-')) {
75
- clone.removeAttribute(at.name)
76
- clone.removeAttribute('p:c')
77
- }
78
- });
79
- // stringHtml+=clone.outerHTML
80
- store.appendChild(clone)
81
- }else{
82
- store.appendChild(clone)
83
- }
84
- template.appendChild(item.element)
85
-
86
- })
66
+ chained.forEach((item) => {
67
+ const clone = item.element.cloneNode(true);
68
+ clone._avoidPawaRender = true;
69
+ Array.from(clone.attributes).forEach(at => {
70
+ if (at.name.startsWith('c-') || at.name === 'p:c') {
71
+ clone.removeAttribute(at.name);
72
+ }
73
+ });
74
+ store.appendChild(clone);
75
+ template.appendChild(item.element);
76
+ });
87
77
  const getRightElement=chainMap.get(latestChain.id)
88
78
  if (getRightElement) {
89
79
  const copyElement=getRightElement.element.cloneNode(true)
@@ -133,31 +123,28 @@ export const Switch = async(el, attr,stream) => {
133
123
  }]
134
124
  const chainMap=new Map()
135
125
  chainMap.set(el.getAttribute('case'),{condition:'case',element:el})
136
- const getChained=(nextSibling)=>{
137
- if (nextSibling !== null) {
138
- if (nextSibling && nextSibling.getAttribute('default') === '' || nextSibling.getAttribute('case')) {
139
- if (nextSibling.getAttribute('case')) {
140
- chained.push({
141
- exp:nextSibling.getAttribute('case'),
142
- condition:'case',
143
- element:nextSibling
144
- })
145
- chainMap.set(nextSibling.getAttribute('case'),{condition:'case',element:nextSibling})
146
- getChained(nextSibling.nextElementSibling)
147
- nextSibling.remove()
148
- }else if (nextSibling.getAttribute('default') === '') {
149
- chained.push({
150
- exp:'false',
151
- condition:'default',
152
- element:nextSibling
153
- })
154
- chainMap.set('default',{condition:'default',element:nextSibling})
155
- nextSibling.remove()
156
- }
157
- }
158
- }
159
- }
160
- getChained(nextSiblings)
126
+ const getChained = (sibling) => {
127
+ while (sibling) {
128
+ const next = sibling.nextElementSibling;
129
+ const isCase = sibling.hasAttribute('case');
130
+ const isDefault = sibling.hasAttribute('default');
131
+
132
+ if (isCase) {
133
+ const exp = sibling.getAttribute('case');
134
+ chained.push({ exp, condition: 'case', element: sibling });
135
+ chainMap.set(exp, { condition: 'case', element: sibling });
136
+ sibling.remove();
137
+ } else if (isDefault) {
138
+ chained.push({ exp: 'false', condition: 'default', element: sibling });
139
+ chainMap.set('default', { condition: 'default', element: sibling });
140
+ sibling.remove();
141
+ } else {
142
+ break;
143
+ }
144
+ sibling = next;
145
+ }
146
+ }
147
+ getChained(nextSiblings)
161
148
  let func=new Map()
162
149
  let current
163
150
  let latestChain
@@ -187,24 +174,18 @@ const switchFunc=el._evaluateExpr(attr.value,el._context,`at switch directive ${
187
174
  let stringHtml=''
188
175
  const template=document.createElement('template')
189
176
  const store=document.createElement('template')
190
- let index=0
191
- chained.forEach(item =>{
192
- const clone=item.element.cloneNode(true)
193
- clone._avoidPawaRender = true
194
- if (index === 0) {
195
- Array.from(clone.attributes).forEach(at => {
196
- if (at.name.startsWith('c-')) {
197
- clone.removeAttribute(at.name)
198
- }
199
- });
200
-
201
- store.appendChild(clone)
202
- }else{
203
- store.appendChild(clone)
204
- }
205
- index++
206
- template.appendChild(item.element)
207
- })
177
+ // let index=0
178
+ chained.forEach((item) => {
179
+ const clone = item.element.cloneNode(true);
180
+ clone._avoidPawaRender = true;
181
+ Array.from(clone.attributes).forEach(at => {
182
+ if (at.name.startsWith('c-') || at.name === 'p:c') {
183
+ clone.removeAttribute(at.name);
184
+ }
185
+ });
186
+ store.appendChild(clone);
187
+ template.appendChild(item.element);
188
+ });
208
189
  el.removeAttribute('switch')
209
190
  const getRightElement=chainMap.get(latestChain.id)
210
191
  if (getRightElement && (current || latestChain.condition === 'default')) {
@@ -394,9 +375,9 @@ export const Key=async(el,attr,stream)=>{
394
375
  const template=document.createElement('template')
395
376
  template.setAttribute('p:store-key',dirId)
396
377
  template.setAttribute('p:store','')
397
- clone.attributes.forEach(at => {
398
- if (at.name.startsWith('c-')) {
399
- clone.removeAttribute(at.name)
378
+ Array.from(clone.attributes).forEach(at => {
379
+ if (at.name.startsWith('c-') || at.name === 'p:c') {
380
+ clone.removeAttribute(at.name);
400
381
  }
401
382
  });
402
383
  template.appendChild(clone)