pawajs 1.4.35 → 1.4.37

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
@@ -295,7 +295,10 @@ export const createIntersectionObserver = (element, observeBy) => {
295
295
  while (instances.length > 0) {
296
296
  const { element: el, func } = instances.shift();
297
297
  if (el) {
298
- if (el._component) el._component.component = compoFunc;
298
+ if (el._component){
299
+ el._component.component = compoFunc;
300
+ el._component.validPropRule=compoFunc?.validateProps || {}
301
+ }
299
302
 
300
303
  keepContext(el._stateContext);
301
304
  el._stateContext._hasRun = false;
@@ -320,6 +323,7 @@ RegisterComponent.lazy=async(...args)=>{
320
323
  if (components.has(name.toUpperCase())) return
321
324
  if (typeof name === 'string' && typeof component === 'function') {
322
325
  if (isServer()) {
326
+ lazyComponents.set(name.toUpperCase(), {name,component});
323
327
  const compo=await component()
324
328
  if (compo[name]) {
325
329
  components.set(name.toUpperCase(),compo[name])
@@ -602,6 +606,20 @@ export const useInsert = (obj = {}) => {
602
606
  }
603
607
  }
604
608
  const createDeepProxy = (target, callback) => {
609
+ // Skip proxies for DOM objects and native objects that don't work well with proxies
610
+ if (target instanceof FileList) return target
611
+ if (target instanceof File) return target
612
+ if (target instanceof Blob) return target
613
+ if (target instanceof FormData) return target
614
+ if (target instanceof Date) return target
615
+ if (target instanceof RegExp) return target
616
+
617
+ // Also skip if it's already a proxy
618
+ if (target && target._isPawaProxy) return target
619
+
620
+ // Also skip if it's a DOM element
621
+ if (target && target.nodeType && typeof target === 'object') return target
622
+
605
623
  return new Proxy(target, {
606
624
  get(target, property) {
607
625
  const value = target[property];
@@ -906,8 +924,9 @@ const component = (el, resume = false, attr, notRender, stopResume) => {
906
924
  if (!lazyComponentElement.has(name)) {
907
925
  createInsectObserver(trackElement,el)
908
926
  }
927
+ }else{
928
+ resumer.resume_component?.(el, attr, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch, { comment, endComment, name, serialized, id, children })
909
929
  }
910
- resumer.resume_component?.(el, attr, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch, { comment, endComment, name, serialized, id, children })
911
930
  }
912
931
  }
913
932
 
@@ -1067,7 +1086,7 @@ const directives = {
1067
1086
  'for-each': For,
1068
1087
  else:(el)=>{el._running =true},
1069
1088
  case:(el)=>{el._running =true},
1070
- default:(el)=>{el._running =true},
1089
+ "s-default":(el)=>{el._running =true},
1071
1090
  'else-if':(el)=>{el._running =true},
1072
1091
  mount: mountElement,
1073
1092
  unmount: unMountElement,
package/merger/switch.js CHANGED
@@ -52,7 +52,7 @@ export const merger_switch=(el,attr,stateContext,resume=false,{comment,endCommen
52
52
  }
53
53
  }
54
54
  const setElement=(newElement,exp)=>{
55
- newElement.removeAttribute(exp)
55
+ newElement.removeAttribute(exp === 'default'?'s-default':exp)
56
56
  if (stateContext._hasRun) {
57
57
  stateContext._hasRun = false
58
58
  keepContext(stateContext)
@@ -153,13 +153,15 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
153
153
  }
154
154
  const context=el._context
155
155
  const propsSetter=()=>{
156
+ const findElement=div.querySelector('[--]') || div.querySelector('[rest]')
157
+ if (findElement) {
158
+ findElement.removeAttribute('--')
159
+ findElement.removeAttribute('rest')
160
+ }
156
161
  if(Object.entries(el._restProps).length > 0){
157
- const findElement=div.querySelector('[--]') || div.querySelector('[rest]')
158
162
  if (findElement) {
159
163
  for (const [key,value] of Object.entries(el._restProps)) {
160
164
  findElement.setAttribute(value.name,value.value)
161
- findElement.removeAttribute('--')
162
- findElement.removeAttribute('rest')
163
165
  }
164
166
  }
165
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "1.4.35",
3
+ "version": "1.4.37",
4
4
  "type":"module",
5
5
  "description": "pawajs library (reactive web runtime) for easily building web ui, enhancing html element, micro frontend etc ",
6
6
  "main": "index.js",
package/pawaElement.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import {components,lazyComponents ,escapePawaAttribute,getPawaAttributes,getDependentAttribute,getPrimaryDirectives } from './index.js';
2
- import {splitAndAdd,replaceTemplateOperators,setPawaDevError,getEvalValues} from './utils.js';
2
+ import {splitAndAdd,replaceTemplateOperators,setPawaDevError,getEvalValues, checkKeywordsExistence} from './utils.js';
3
3
  import PawaComponent from './pawaComponent.js';
4
4
  import { createIntersectionObserver } from './index.js';
5
5
  import { addLazyComponentElement } from './index.js';
@@ -51,9 +51,9 @@ export class PawaElement {
51
51
  return Array.from(this._el.children)
52
52
  }
53
53
  checkLazy(){
54
- if (lazyComponents.has(this._el.tagName)) {
54
+ if (lazyComponents.has(splitAndAdd(this._el.tagName))) {
55
55
  this._lazy=true
56
- if (!lazyComponentElement.has(this._el.tagName)) {
56
+ if (!lazyComponentElement.has(splitAndAdd(this._el.tagName))) {
57
57
  createIntersectionObserver(this._el)
58
58
  }
59
59
  }
@@ -293,14 +293,49 @@ export class PawaElement {
293
293
  const pawaAttribute=getPawaAttributes()
294
294
  const dependAttribute=getDependentAttribute()
295
295
  this._attributes.forEach((attr) => {
296
+
296
297
  if (!attr.name.startsWith(':') && !pawaAttribute.has(attr.name) && !dependAttribute.has(attr.name)) {
297
298
  let name=''
298
- if (attr.name.startsWith('-')) {
299
- name=attr.name.slice(1)
300
- } else {
301
- name=attr.name
299
+ if (attr.name.startsWith('-')) {
300
+ name=attr.name.slice(1)
301
+ } else {
302
+ name=attr.name
303
+ }
304
+ const context=this._context
305
+ const setProps=()=>{
306
+ delete this._restProps[name]
307
+ let value=attr.value
308
+ if (value.includes('@{')) {
309
+ const regex = /@{([^}]*)}/g;
310
+ value = value.replace(regex, (match, expression) => {
311
+ if (checkKeywordsExistence(this._staticContext, expression)) {
312
+ return value
313
+ } else {
314
+ const res = this.safeEval(context, expression, 'props', true)
315
+ return res
316
+ }
317
+ });
318
+ return value
319
+ }else if( attr.name.startsWith('on-') || attr.name.startsWith('out-')){
320
+ const res=this.safeEval(context,`(e)=>{
321
+ ${attr.value}
322
+ }`, 'props',true)
323
+ return res
324
+ }
325
+ return attr.value
326
+ }
327
+
328
+ if (this._props[name] || name === 'class' && this._props['className'] || name === 'defaultValue' && this._props['defaultValue']) return
329
+ name=name.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
330
+ if (name === 'class') {
331
+ this._props['className']=setProps
332
+ }else if(name === 'default'){
333
+ this._props['defaultValue']=setProps
334
+ }else{
335
+ this._props[name]=setProps
302
336
  }
303
- this._restProps[name]={name:name,value:attr.value}
337
+
338
+ this._restProps[name]={name:name,value:attr.value}
304
339
  }else if(!pawaAttribute.has(attr.name) && attr.name.startsWith(':')){
305
340
 
306
341
  const propsName=attr.name.slice(1)
package/power.js CHANGED
@@ -222,7 +222,7 @@ export const Switch = (el, attr, stateContext,resume=false,notRender,stopResume)
222
222
  chainMap.set(nextSibling.getAttribute('case'),{condition:'case',element:nextSibling})
223
223
  getChained(nextSibling.nextElementSibling)
224
224
  nextSibling.remove()
225
- }else if (nextSibling.getAttribute('default') === '') {
225
+ }else if (nextSibling.getAttribute('s-default') === '') {
226
226
  chained.push({
227
227
  exp:'false',
228
228
  condition:'default',
package/utils.js CHANGED
@@ -176,7 +176,12 @@ export const sanitizeTemplate = (temp) => {
176
176
  };
177
177
 
178
178
  export const ComponentProps=(somes,message,name,key)=>{
179
- let some=somes?.() || somes
179
+ let some
180
+ if (typeof somes === 'function') {
181
+ some=somes()
182
+ }else{
183
+ some=somes
184
+ }
180
185
  return({
181
186
  Array:()=>{
182
187