-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
75 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "repeater-scope", | ||
"version": "1.0.0", | ||
"description": "Create handlers for the repeater items", | ||
"main": "src/index.js", | ||
"scripts": {}, | ||
"sideEffects": false, | ||
"keywords": [ | ||
"wix", | ||
"corvid", | ||
"wixcode", | ||
"editorx", | ||
"velo" | ||
], | ||
"author": { | ||
"name": "Alexander Zaytsev", | ||
"email": "[email protected]", | ||
"url": "https://twitter.com/_shoonia" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/shoonia/repeater-scope.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/shoonia/repeater-scope/issues" | ||
}, | ||
"homepage": "https://github.com/shoonia/repeater-scope#readme", | ||
"license": "MIT" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { createScope } from './createScope'; | ||
export { useScope } from './useScope'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Use Repeater Scope | ||
* https://github.com/shoonia/repeater-scope | ||
* | ||
* @typedef {{ | ||
* _id: string; | ||
* [key: string]: any; | ||
* }} ItemData; | ||
* | ||
* @typedef {{ | ||
* $item: $w.$w; | ||
* itemData: ItemData; | ||
* index: number; | ||
* data: ItemData[]; | ||
* }} ScopeData; | ||
* | ||
* @param {$w.Event} event | ||
* @returns {ScopeData} | ||
*/ | ||
export const useScope = (event) => { | ||
const ctx = event.context; | ||
const find = (i) => i._id === ctx.itemId; | ||
|
||
let repeter = event.target; | ||
// @ts-ignore | ||
while ((repeter = repeter.parent).type !== '$w.Repeater'); | ||
|
||
return { | ||
// @ts-ignore | ||
$item: $w.at(ctx), | ||
|
||
get itemData() { | ||
return repeter.data.find(find); | ||
}, | ||
|
||
get index() { | ||
return repeter.data.findIndex(find); | ||
}, | ||
|
||
get data() { | ||
return repeter.data; | ||
}, | ||
}; | ||
}; |