BigJk / snd

Sales & Dungeons — Thermal Printer as D&D / TTRPG Utility
https://sales-and-dungeons.app/
MIT License
500 stars 17 forks source link

Add optional schema definitions to data skeleton #25

Open BigJk opened 1 year ago

BigJk commented 1 year ago

Currently the "schema" of a templates data is derived kinda vaguely from the data skeleton. This is a relic from S&D just being a small proof-of-concept type of application at the beginning. Defining a image in the data skeleton already introduced a additional syntax inside the JSON.

{
  "icon": "!IMAGE"
}

it the future it should be possible to OPTIONALLY define what input should be shown for a field + some kind of default value for a preview while editing. A example to illustrate the idea:

{
  "name": "!TEXT=Default Name",
  "description": "!TEXTAREA=Some long default text",
  "number": "!NUMBER=0",
  "dropdown": "!DROPDOWN:A,B,C=A"
}

That way we can map custom components to the same data types and which should make entry creation and editing more pleasant.

carlosfrodrigues commented 1 year ago

Hi, I'm interested in this one. Could you assign this for me?

BigJk commented 1 year ago

@carlosfrodrigues Thanks for your interest. Feel free to just fork the project and start hacking 😃 I'm always open to merging pull requests that seems reasonable. If any questions come up we can discuss them here or over discord.

Some thoughts

Objects and Arrays of Objects

Something that should be thought about is how the handling of sub-objects, arrays of objects, arrays of objects in sub-objects... should be handled in regards to the schema. Imagine the following data:

{
    "obj": { "field_a": "test", "field_b": 1234 },
    "arr": [
        { "field_a": "test", "field_b": 1234 },
        { "field_a": "test", "field_c": ["a", "b", "c"] } 
     ]
}

How should this be described by the schema?

{
    "obj": { "field_a": "!TEXT=default", "field_b": "!NUMBER=1234" },
    "arr": [
        // Do we describe the schema of the elements in a array
        // by inserting a single object with definitions?
        {
            "field_a": "!TEXT=default",
            "field_b": "!NUMBER=1234",
            "field_c": "!MULTI_OPT:a,b,c=a"
        }
     ]
}

I feel like there are a lot of questions that might need to be investigated before actually implementing something.

Feel free to share your thoughts 😃

carlosfrodrigues commented 1 year ago

Hi @BigJk ! 👋

I've just submitted a pull request (#50) for review. Please note that this PR is primarily for review purposes, and some functionalities, like the dropdown, are not yet fully functional.

I'd really appreciate it if you could take some time to review the changes I've made so far and provide feedback. Once we address the remaining issues, I'll ensure everything works smoothly.

Thank you for your attention and feedback! 🙏