Comments (3)
@mrsunshine got it. Thanks for the clarification and thanks for providing this code snippet, which can be useful for others looking at this issue in the future 🙂 We will create an internal ticket to discuss about this, but I cannot tell any ETA, and whether or not we will ship this, though. Thanks for your contribution 💙
from field-plugin.
@eunjae-lee yes. All informations are there but difficult to access.
Imagine you have field A and your field type plugin in the same block. Inside your field type plugin you want to use the value of the field A. Currently you have to use plugin.data.blockUid to recursively search through data.story.content to find the block object with blockUid.
For easy use it would be helpfull to have either:
- the block object where the field type plugin on the root level plugin.data.block
- or a helper function which returns a block object by UUID
something like this:
...
const blockUid: string = plugin?.data?.blockUid || ''
const contentObj: Object | undefined = data?.story?.content;
const myBlock = searchBlock(contentObj, blockUid);
const searchBlock = (obj: Block, uid: string): Block | null => {
if (obj._uid === uid) {
return obj;
}
// Check nested objects and arrays
for (let key of Object.keys(obj)) {
const value = obj[key];
if (Array.isArray(value)) {
for (let item of value) {
let result = searchBlock(item, uid);
if (result) {
return result;
}
}
} else if (typeof value === 'object' && value !== null) {
let result = searchBlock(value, uid);
if (result) {
return result;
}
}
}
return null; // Return null if the block is not found
}
from field-plugin.
Hi @mrsunshine thanks for reaching out to us. If I understand this correctly, do you want a field plugin to be able to access other fields in the current story via blockUid?
from field-plugin.
Related Issues (20)
- Use data source for options HOT 4
- Sandbox not working in the browser Brave due to ad blocker HOT 1
- Multirepo pnpm install fails after creation HOT 8
- Wrong modal iframe heigth HOT 5
- Visual Editor does not detect changes in custom field plugin HOT 6
- Possibility to edit complete data structure in Field Plugin Sandbox HOT 3
- Access FieldPlugin options from within validateContent HOT 1
- Cannot find module '@storyblok/field-plugin/test' or its corresponding type declarations. HOT 3
- Add selected interface app language HOT 2
- Vue3 plugin options from useFieldPlugin hook is `undefined` HOT 2
- Field Plugin height is not correctly updated HOT 1
- [sandbox] Preserve settings in URL query parameters for easy sharing HOT 1
- Extend CLI with --publish flag option configurable
- Extend CLI deploy command with --spaces flag option configurable HOT 4
- Extend CLI to enable deleting field-type plugins HOT 4
- Field plugins do not work on domains other than app.storyblok.com
- Vite 5 support ?
- Default options not working HOT 4
- "actions.selectAsset()" only returns the filename but not things like Alt Text or Asset ID HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from field-plugin.