Hi,
If you work with static files, with no database, then you can save the workspace, stringify, and encode as url. This will create a huge url with data but it works.
to create the link:
let saveobj = Blockly.serialization.workspaces.save(Index.workspace);
let saveStr = JSON.stringify(saveobj);
let saveEncoded = encodeURIComponent(saveStr);
let url = window.top.location.pathname;
console.group('share');
console.log(url + '?share=' + saveEncoded, '_blank');
console.groupEnd();
the link will be available in console.log
for the page that open that link, you can use this code.
let query = location.search.slice(1);
let queryAr = query.split('&');
let kvAr: { key: string, value: string }[] = [];
queryAr.forEach((item) => {
let ar = item.split('=');
kvAr.push({
key: ar[0],
value: ar[1]
})
})
kvAr.forEach((item) => {
if (item.key == 'share') {
let value = decodeURIComponent(item.value);
let code = JSON.parse(value);
Blockly.serialization.workspaces.load(code, Index.workspace);
}
})
Index.workspace is the reference to the workspace.
You can use url shortener to shorten the url. this must be done manually.
sample url:
https://shorturl.at/DPQ23this url will open workspace for my project and setup the workspace based on data in url.
the best solution would be to setup a database, otherwise, this just work.