accordproject / template-playground

Web Playground for TemplateMark templates
https://playground.accordproject.org
Apache License 2.0
15 stars 18 forks source link

Provide functionality to generate shareable links that include the encoded template data. #48

Closed sanketshevkar closed 2 weeks ago

sanketshevkar commented 2 months ago

Feature Request 🛍️

Use Case

Possible Solution

Context

Detailed Description

sanketshevkar commented 1 month ago

I found this. And looked around, looks like this is a standard approach. What is happening here?

Questions to be investigated here:

cc: @Vinyl-Davyl @mttrbrts @dselman

sanketshevkar commented 1 month ago

If we are going to use query parameters for state sharing, does saving the data in local storage still makes sense? The state in local storage is usually mapped to the URL. If we are storing the state in the URL itself. Should we even worry about storing it locally? https://github.com/accordproject/template-playground/issues/47

sanketshevkar commented 1 month ago

@mttrbrts had started discussion around if we would like to support uploading template-archive templates to load that template in the playground. In my view it'll be good if we keep this out of the scope for milestone 2. If we have time after milestone 3. This is something we should be looking into.

But we should start the discussion here, as the solution we build in this milestone should be extensible when we decide to develop the feature to upload and download a template.

I was wondering if could add the compression and base-64 encoding logic to template-archive itself and use it in playground? Something like getHash.

mttrbrts commented 1 month ago

This looks like a great place to start, @sanketshevkar

I'm interested to know how far this can take us. For example, what is the expected upper bound on the maximum size of the template that can be expressed in this format?

Vinyl-Davyl commented 2 weeks ago

Hey guys, having done some work and taking inspiration from TS playground on the use and Implementation with LZ-String. I believe our threshold is 2mb max size, which I think is okay for us.

Would share some more details soon.

Vinyl-Davyl commented 2 weeks ago

Hey Guys,

After exploring the TS playground and implementing similar functionality in our project using LZ-String, I wanted to share our approach and findings regarding the state sharing and template size considerations and from what I've been building:

Our Approach to State Sharing:

  1. Stringifying and Compression: We stringify our state object due to the challenge of directly storing complex JSON nested objects in URLs.
  2. Compression with LZ-String: We use LZ-String for lossless compression to minimize the size of the state data.
  3. Base64 Encoding: Post compression, perharps we base64 encode the compressed string. This is necessary because the compressed data might contain binary data which cannot be directly shared in query parameters.

Size Considerations:

Future Considerations:

Project Milestones:

Based on these findings and implementation inspired by TS playground utilizing the compression library LZ-String, our approach supports efficient state sharing via URL while considering browser compatibility and file size constraints. This sets a strong foundation for future enhancements, such as template-archive integration and additional features post-Milestone 3.

Hence, Work has commenced on this.

Would love to discuss further and iterations on these insights to ensure our approach aligns with project goals and future scalability.

cc: @sanketshevkar @mttrbrts @dselman