pawajs 1.4.3 → 1.4.5

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/CHANGELOG.md CHANGED
@@ -1,3 +1,4 @@
1
1
  CHANGELOG.md
2
2
  + version 1.3.0 - v1.4.0 on experiment
3
3
  + version 1.4.0 for-key bug fixing
4
+ + version 1.4.4 added onSuspense and fix out- (document event)
package/README.md CHANGED
@@ -281,6 +281,12 @@ For handling DOM events.
281
281
  <button on-click="addTodo()">Add Todo</button>
282
282
  <input on-input="newTodoText.value = e.target.value" />
283
283
  ```
284
+ #### `out-<event>`
285
+ For handling DOM events.
286
+
287
+ ```html
288
+ <button out-click="console.log('outside')">Add Todo</button>
289
+ ```
284
290
 
285
291
  ### Component Props
286
292
 
package/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  export interface PawaElement extends HTMLElement {
3
3
  _running: boolean;
4
4
  _context: any;
5
- _staticContext: any[];
5
+ _staticContext: Array<string>;
6
6
  _resetEffects: Set<Function>;
7
7
  _avoidPawaRender: boolean;
8
8
  _el: HTMLElement;
@@ -188,8 +188,6 @@ export function getPawaAttributes(): Set<string>;
188
188
 
189
189
  export function getPrimaryDirectives(): Set<string>;
190
190
 
191
- export function setError(params: { error: any }): void;
192
-
193
191
  /**
194
192
  * Registers components for use in templates.
195
193
  * @param {...(string | Function)} args - Component functions or (name, function - done by pawajs-vite-plugin automaticly) pairs.
@@ -264,8 +262,9 @@ export function useServer<T = Record<string, any>>(): {
264
262
  * Stores the component instance into the returned $async hook.
265
263
  * Used in async component.
266
264
  * Must be called before any await call
265
+ * + uses onSuspense for loading state before any await
267
266
  */
268
- export function useAsync(): { $async: <T>(callback: () => T) => T };
267
+ export function useAsync(): { $async: <T>(callback: () => T) => T ,onSuspense:(html:string)=>void};
269
268
 
270
269
  /**
271
270
  * Returns TRUE when pawajs is in continous rendering mode from ssr
package/index.js CHANGED
@@ -105,7 +105,11 @@ const createPawaDev = () => {
105
105
  if (warn) {
106
106
  console.warn(msg, stack, template, el,directives)
107
107
  } else {
108
- console.error(msg, stack, template, el)
108
+ if (typeof window === 'undefined') {
109
+ console.error(msg, stack, template)
110
+ }else{
111
+ console.error(msg, stack, template, el)
112
+ }
109
113
  }
110
114
  },
111
115
  logRender: (component, time) => {
@@ -320,6 +324,7 @@ let stateContext = {
320
324
  _formerContext: null,
321
325
  _insert: {},
322
326
  _resume: false,
327
+ _suspense:'',
323
328
  _hook: {
324
329
  effect: [],
325
330
  isMount: [],
@@ -365,19 +370,6 @@ export const getDependentAttribute = () => dependentPawaAttribute
365
370
  export const getPawaAttributes = () => {
366
371
  return pawaAttributes
367
372
  }
368
- export const setError = ({ error }) => {
369
- if (!client) return
370
- if (!stateContext) {
371
- console.warn('must be used inside of a component')
372
- return
373
- }
374
- if (!stateContext._hasRun) {
375
- if (!stateContext?._error) {
376
- stateContext._error = []
377
- }
378
- stateContext?._error.push(error)
379
- }
380
- }
381
373
 
382
374
  /**
383
375
  *
@@ -465,7 +457,7 @@ export const runEffect = (callback, deps) => {
465
457
  }
466
458
 
467
459
  /**
468
- *
460
+ * to validate component for runtime rules
469
461
  * @param {object} props
470
462
  * @returns {object}
471
463
  */
@@ -478,6 +470,7 @@ export const useValidateComponent = (component, object) => {
478
470
  }
479
471
  /**
480
472
  * @returns {{id:string,setValue:()=>void}}
473
+ * + Sets the context
481
474
  */
482
475
  export const setContext = () => {
483
476
  if (client) {
@@ -533,7 +526,7 @@ export const useContext = (context) => {
533
526
  }
534
527
 
535
528
  /**
536
- * Get Current component context from the html
529
+ * Get Current component context from the html (the component parent)
537
530
  * @returns {object}
538
531
  */
539
532
  export const useInnerContext = () => {
@@ -592,16 +585,22 @@ export const useAsync = () => {
592
585
  storeContext._hasRun = true
593
586
  stateContext = null
594
587
  return res
588
+ },
589
+ onSuspense:(html)=>{
590
+ storeContext._suspense=html
595
591
  }
596
592
  }
597
593
  } else {
594
+ //sets server initialization to default
598
595
  return {
599
596
  $async: (callback) => {
600
597
  return callback()
601
- }
598
+ },
599
+ onSuspense:(html)=>{}
602
600
  }
603
601
  }
604
602
  }
603
+ //resume state during after ssr
605
604
  export const isResume = () => {
606
605
  if (client) {
607
606
  return stateContext._resume
@@ -664,6 +663,7 @@ export const setStateContext = (context) => {
664
663
  stateContext._reactiveProps = {}
665
664
  stateContext._template = ''
666
665
  stateContext._resume = false
666
+ stateContext._suspense=''
667
667
  stateContext._hook={
668
668
  beforeMount:[],
669
669
  reactiveEffect:[],
@@ -854,7 +854,7 @@ const component = (el, resume = false, attr, notRender, stopResume) => {
854
854
  return
855
855
  }
856
856
  el._running = true
857
-
857
+
858
858
  if (!resume) {
859
859
  normal_component(el, stateContext, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch)
860
860
  } else {
@@ -1257,6 +1257,8 @@ const Pawa = {
1257
1257
  setContext,
1258
1258
  $state,
1259
1259
  pawaStartApp,
1260
+ useAsync,
1261
+ useInnerContext,
1260
1262
  RegisterComponent,
1261
1263
  runEffect,
1262
1264
  html
@@ -78,31 +78,45 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
78
78
  const storeContext=stateContexts
79
79
  let compo
80
80
  let awaits=false
81
+ let suspense=''
81
82
  try {
82
83
  if(done){
83
84
  const compoCall=component.component(app)
84
85
  if( compoCall instanceof Promise){
86
+ suspense=stateContexts._suspense || ''
87
+
85
88
  awaits=true
86
89
  compoCall.then((res)=>{
87
90
  div.innerHTML=res
91
+ let promise
92
+ if (comment.nextSibling !== endComment) {
93
+ promise= pawaWayRemover(comment,endComment)
94
+ }
88
95
  propsSetter()
89
- if (storeContext._hasRun) {
90
- storeContext._hasRun = false
91
- keepContext(storeContext)
92
- }if (storeContext?._insert) {
93
- Object.assign(el._context,storeContext._insert)
94
- }
95
- childInsert()
96
- lifeCircle()
97
- storeContext._hasRun=true
98
- stateContext=null
99
- })
96
+ Promise.all([promise]).then(()=>{
97
+ if (storeContext._hasRun) {
98
+ storeContext._hasRun = false
99
+ keepContext(storeContext)
100
+ }if (storeContext?._insert) {
101
+ Object.assign(el._context,storeContext._insert)
102
+ }
103
+ childInsert(false)
104
+ lifeCircle()
105
+ storeContext._hasRun=true
106
+ stateContext=null
107
+ })
108
+ })
100
109
  }else if (compoCall !== undefined){
101
110
  compo= sanitizeTemplate(compoCall)
102
111
  }
103
112
  }else{
104
113
  compo=""
105
114
  }
115
+ if (awaits && suspense) {
116
+
117
+ compo= sanitizeTemplate(suspense)
118
+ }
119
+
106
120
  } catch (error) {
107
121
  setPawaDevError({
108
122
  message:`error from ${el._componentName} component ${error.message}`,
@@ -138,9 +152,11 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
138
152
  }
139
153
  }
140
154
 
141
- const childInsert=()=>{
142
- el._component?._hook?.beforeMount?.forEach((bfm) => {
143
- bfm._sent=true
155
+ const childInsert=(awaiting)=>{
156
+ // console.log(stateContexts._insert)
157
+ if (awaiting === false) {
158
+ el._component?._hook?.beforeMount?.forEach((bfm) => {
159
+ bfm._sent=true
144
160
  const result= bfm(comment)
145
161
  if (typeof result === 'function') {
146
162
  el._unMountFunctions.push(result)
@@ -148,18 +164,19 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
148
164
  })
149
165
 
150
166
  el._component?._hook?.isMount.forEach((hook) => {
151
- hook._sent=true
152
- el._MountFunctions.push(hook)
167
+ hook._sent=true
168
+ el._MountFunctions.push(hook)
153
169
  })
154
170
  el._component?._hook?.isUnMount.forEach((hook) => {
155
- hook._sent=true
156
- el._unMountFunctions.push(hook)
171
+ hook._sent=true
172
+ el._unMountFunctions.push(hook)
157
173
  })
158
- const child=div.children[0]
159
-
160
- if (child !== null ) {
161
- if (child) {
162
- endComment.parentElement.insertBefore(child, endComment)
174
+ }
175
+ const child=div.children[0]
176
+
177
+ if (child !== null ) {
178
+ if (child) {
179
+ endComment.parentElement.insertBefore(child, endComment)
163
180
 
164
181
  stateContexts?._error?.forEach((error) => {
165
182
  throw Error(error)
@@ -168,7 +185,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
168
185
  }
169
186
  }
170
187
  }
171
- if(awaits === false)childInsert();
188
+ childInsert(awaits?true:false);
172
189
  const lifeCircle=()=>{
173
190
  Promise.resolve().then(()=>{
174
191
  el._component?._hook?.effect.forEach((hook) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "type":"module",
5
5
  "description": "pawajs library (html runtime) for easily building web ui, enhancing html element, micro frontend etc ",
6
6
  "main": "index.js",
@@ -24,5 +24,6 @@
24
24
  "bugs": {
25
25
  "url": "https://github.com/Allisboy/pawajs/issues"
26
26
  },
27
- "homepage": "https://github.com/Allisboy/pawajs#readme"
27
+ "homepage": "https://github.com/Allisboy/pawajs#readme",
28
+ "website": "https://pawajs.vercel.app"
28
29
  }
package/power.js CHANGED
@@ -343,7 +343,7 @@ export const documentEvent = (el, attr) => {
343
343
  const resolvePath = (path, obj) => {
344
344
  return path.split('.').reduce((acc, key) => acc?.[key], obj);
345
345
  };
346
- const func = new Function('e', ...keys, `
346
+ const func = new Function('e','$element', ...keys, `
347
347
  try{
348
348
  ${attr.value}
349
349
  }catch(error){
@@ -352,9 +352,9 @@ export const documentEvent = (el, attr) => {
352
352
  }`)
353
353
  const values = keys.map((key) => resolvePath(key, el._context));
354
354
  const functions = (e) => {
355
- try {
356
-
357
- func(e, ...values)
355
+ try {
356
+ const $element=el
357
+ func(e,$element, ...values)
358
358
  } catch (error) {
359
359
  setPawaDevError({
360
360
  message: `Error from out-${eventName} directive ${error.message}`,
@@ -364,15 +364,14 @@ export const documentEvent = (el, attr) => {
364
364
  }
365
365
  }
366
366
  el.removeAttribute(attr.name)
367
- setTimeout(() => {
367
+ el._MountFunctions.push( ()=> {
368
368
  document.addEventListener(eventName, functions)
369
- }, 1000)
369
+ })
370
370
 
371
371
  const unMount = () => document.removeEventListener(eventName, functions);
372
372
  el._setUnMount(unMount)
373
373
 
374
374
  }
375
-
376
375
  export const exitTransition=(el,attr)=>{
377
376
  if (el._running) {
378
377
  return