T
TyphonJSNekro Darkmoon

setPosition in SvelteApplication

The SvelteApplication class has a function called setPosition that is there to support core behavior. And while it exists and is called when opening the app. It isn't really called when minimizing, maximizing, or changing the position of the window itself. This means that any modules that try to wrap the setPosition function to extend features fail to do so.
TM
TyphonJS (Michael)99d ago
Well you shouldn't wrap it per se. What type of feature are you trying to implement? The TRL / TJSPosition implementation is quite a bit richer. Quite likely there is an alternate way to accomplish most things.
ND
Nekro Darkmoon99d ago
I'm not the one trying to wrap the function in this case core foundry uses sheet.setPosition to change the position of sheets. Module makers that change the behavior of this function to add more functionality like attach other windows to the sheet generally wrap this function either manually or using libwrapper. And because SvelteApplication doesn't call setPosition while changing the position of the sheet means it breaks compatibility with all the other modules.
TM
TyphonJS (Michael)99d ago
Indeed any module being refactored / rewritten for TRL may need to change a thing or two depending on the goals being accomplished. In TRL app.position is a store, so it can be subscribed to for implementations of attaching / following a target apps position. There is also a robust validation stage that can have user added validators for restricting movement / also useful for docking. So, unless it was a really strange use case there should be a cleaner way to implement the feature w/ TRL
ND
Nekro Darkmoon99d ago
the problem is that other modules don't use TRL 😄
TM
TyphonJS (Michael)99d ago
Ah, so you are saying that there is a module out there that somehow affects the position of apps it doesn't own? Got an example of such a module?
ND
Nekro Darkmoon99d ago
ripper's paper doll is one example
ND
Nekro Darkmoon99d ago
No description
ND
Nekro Darkmoon99d ago
honestly a lot of modules do similar things with other functions as well
TM
TyphonJS (Michael)99d ago
setPosition should be the only function where control flow is altered w/ TRL, so other Application functions are not diverted to an alternate implementation. In the paper doll example a small change would be needed to subscribe to the position changes of the host sheet. Not that this is a great solution.. Just a brainstorm hack I haven't tried. Because you have a system and can test against paper doll. Add this.position.subscribe((pos) => this.setPosition(pos)); to the constructor of your sheet. I'm not saying this is a good solution, but curious if that works or blows up.. ;P
ND
Nekro Darkmoon99d ago
yeah already tried that 😄 it's an infinite loop 😄
TM
TyphonJS (Michael)99d ago
Yeah.. I'd have to check it out. Technically it should reject follow up position setting if the data is the same as current state, so I'll take a look at that. Not that the hack mentioned above is a good solution. It is a bit of a rub because the TRL position system is backward compatible with Foundry core except for the use case of an external module trying to integrate in an ad hoc manner with Applications it doesn't control.
ND
Nekro Darkmoon99d ago
technically this can be resolved with changing the 3 instances of this.position.set to this.setPosition. actually no 🤔 need to double check something 😄
TM
TyphonJS (Michael)99d ago
I'll have to take a look. There is the draggable action / implementation that is the sticking point quite likely. This is in the platform neutral implementation for TJSPosition, so not at the Foundry integration layer: https://github.com/typhonjs-svelte/runtime-base/blob/main/src/svelte/store/position/action/draggable.js#L224
ND
Nekro Darkmoon99d ago
prolly core foundry calls app.setPosition
TM
TyphonJS (Michael)99d ago
Yes.. The TJSPosition implementation is platform neutral and can be applied to any element to make something positionable / draggable, etc. It's not a hard coded 1:1 relationship to a specific implementation ala app.setPosition. Given that all of this could be upended with the v12 App v2 API I'd want to wait just a bit more to see how much damage that may cause. If Foundry core drastically changes how position state is stored or accessed there will be other aspects to work around and consider. I've been mum on trying to contact Atro and just not draw attention to this potential situation. The likelihood is that app.position as an object storing positional data will survive the App v2 changes. It may not though. --- All of this again is just a sticking point for "unclean" hackery of external modules which is the exception to the rule.
ND
Nekro Darkmoon99d ago
ok I've made a workaround
TM
TyphonJS (Michael)99d ago
Do share.. I'll be at a computer soon.
ND
Nekro Darkmoon99d ago
constructor() {
...
this.position.subscribe((pos) => this.setPosition(pos, false));
}

setPosition(pos: any, propagate = true): any {
if (!propagate) return this.position.get();
return super.setPosition(pos);
}
constructor() {
...
this.position.subscribe((pos) => this.setPosition(pos, false));
}

setPosition(pos: any, propagate = true): any {
if (!propagate) return this.position.get();
return super.setPosition(pos);
}
ND
Nekro Darkmoon99d ago
result
TM
TyphonJS (Michael)99d ago
Nice.. Yeah. I was going to check out potential solutions that required a small override to setPosition, but the above is a good take at it. Now... This works in the adhoc use case of paper doll, but perhaps may fail to work when an external module tries to change the position data versus just plug into getting a hard coded callback that just some position changed of an external app.
ND
Nekro Darkmoon99d ago
yup
TM
TyphonJS (Michael)99d ago
It's conceivably possible to just make a "Foundry" implementation of draggable or just add the overridden setPosition implementation you came up with to SvelteApplication, but it really makes sense to wait until there is more details / access to App v2 before implementing anything. Essentially the current SvelteApplication implementation is going to be transferred to the legacy sub-path export #runtime/svelte/application/legacy and then a new App v2 implementation will be made as presumably there will be changes.
ND
Nekro Darkmoon99d ago
yup I'd deffo wait till application v2 before making any changes honestly
TM
TyphonJS (Michael)99d ago
It is a low volume nuisance really just for system developers too. I don't think there are modules that try to do something to other modules in the same manner as paper doll does in respect to actor sheets.
ND
Nekro Darkmoon99d ago
a lot of modules do actually just not with sheets usually it's usually with other parts of the system
midi,
dae,
better-rolls,
midi,
dae,
better-rolls,
the list goes on Honestly, the way modules change stuff is by wrapping the original functions of sheets, documents, etc
TM
TyphonJS (Michael)99d ago
For sure, but from a UI / control perspective it should be rare or non-existent that a module tries to change the behavior of another module. The paper doll situation is system specific for actor sheets.
ND
Nekro Darkmoon99d ago
Yeah Core foundry doesn't really have a hook for position change of a sheet So stuff like this ends up being needed Hopefully all these little things will be better with Appv2
TM
TyphonJS (Michael)99d ago
Yeah.. I hope so too. I wished I had a better working relationship with Atro and the core team to be able to communicate lessons learned. You could drop in the TRL position implementation (which is JS) right in and get tremendous benefits. I want to remain positive that good things will come from App v2, but I expect it to be flawed as UI / UX is not a strong point of the core team. I remain hopefull nonetheless. Just as a note too re: no hook for position changes. If the TRL / TJSPosition implementation was the standard these kinds of problems would go away because app.position can be subscribed to. And if an external module wants to alter validation of position changes there is the validator API of TJSPosition: https://typhonjs-fvtt-lib.github.io/api-docs/classes/_runtime_svelte_store_position.AdapterValidators.html I definitely should try and get a demo of the validator API into essential-svelte-esm at some point.
Want results from more Discord servers?
Add your server
More Posts
TJSDocument delete actionWhen emitting this event, TJSDocument passes "undefined" as the first argument instead of the documeQuest Log Permissions / InfoHI @larsvonawesome. You asked: > Trying to find more info on Forien's Quest Log; I'm having an issueCreating a derived reducer for a DynMapReducerDo you have an example of how to make a derived reducer for a reducer that's not part of a TJSDcoumeQuest Log objective counts not displayingHi there. the Quest Log objectives (done/total) don't seem to change when I mark quests as completeItem Piles: AuctioneerA few people in the League & some that I know personally have commissioned an Item Piles powered aucSvelecte AlternativesI'm looking to implement a searchable list of sorts, and I found Svelecte: <https://mskocik.github.iSetting up TRL / contributing to existing module (Item Piles)Hi @Paith. I have started this forum post where we can continue to discuss setting up TRL and gettinReactivty and prepareDerivedDataFrom @Wasp > So I'm using prepareDerivedData to, well, derive some data for my items; some of them aLocal Development w/ NPM LinkFrom @Gerark: > Hello! this is probably a base webdev question but I can't find a good reference forIssues Configuring TyphonJS in TSI'm receiving this message in my TS Files: `Cannot find module '#runtime/svelte/application' or its TRL / Svelte based game systemsThis post is a list of repos for game systems built with TRL / Svelte for Foundry. Please DM me if yList of TjsdocumentsLink to original response: https://discord.com/channels/737953117999726592/1067337319041998869/11562Is there a way to export the quest log?I'm trying to setup a world for the PF2E Beginner Box but right now I working in a beta testing worFabricate@MisterPotts. Just starting a forum post to keep track of the conversation. > Fabricate doesn't maSvelte 5 TJSDocument PrototypeGreets @FVTT ▹ Developer. As some of you might have seen there is a bit of paradigm shift that is Funky interaction with fokus managementTJS's Focus Management is creating fun issues for me again. focusKeep = true causes my drag and dropHow to get rid of funky Prosemirror overlapHi. I'm getting some overlap with Prosemirror (see image) any ideas how to avoid that? ``` "@tyFQL / TextEditor enrichment issueFrom @ooblekie: > can anyone give me a hand as to why the text keeps coming up as object promise inTJSDocument not working properly with Module Sub-Types (Data Models)In Foundry, modules can define a [Sub-Types](<https://foundryvtt.com/article/module-sub-types/>) usiTRL `0.1.2` - Fine Tuning releaseGreets @FVTT ▹ Developer! I have just released a fine tuning release that brings a few more feature