SPA
This commit is contained in:
parent
f16394f258
commit
9651d84dc4
8 changed files with 239 additions and 207 deletions
|
|
@ -1,26 +1,7 @@
|
|||
/*
|
||||
Crafter.CppDOM
|
||||
Copyright (C) 2025 Catcrafts
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
export module Crafter.CppDOM:BindingsExport;
|
||||
import std;
|
||||
import :EventTypes;
|
||||
import :BindingsImport;
|
||||
|
||||
export namespace Crafter::CppDOMBindings {
|
||||
std::int32_t clickHandlerMaxId = 0;
|
||||
|
|
@ -95,6 +76,9 @@ export namespace Crafter::CppDOMBindings {
|
|||
std::int32_t dragLeaveHandlerMaxId = 0;
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* dragLeaveHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t popStateHandlerMaxId = 0;
|
||||
std::unordered_map<std::int32_t, std::function<void(void)>>* popStateHandlers = new std::unordered_map<std::int32_t, std::function<void(void)>>();
|
||||
|
||||
std::int32_t fetchHandlerMaxId = 0;
|
||||
std::unordered_map<std::int32_t, std::function<void(std::string)>>* fetchHandlers = new std::unordered_map<std::int32_t, std::function<void(std::string)>>();
|
||||
}
|
||||
|
|
@ -213,6 +197,10 @@ extern "C" {
|
|||
Crafter::CppDOMBindings::fetchHandlers->find(handlerID)->second(response);
|
||||
Crafter::CppDOMBindings::fetchHandlers->erase(handlerID);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecutePopStateHandler"))) void ExecutePopStateHandler(std::int32_t handlerID) {
|
||||
Crafter::CppDOMBindings::popStateHandlers->find(handlerID)->second();
|
||||
}
|
||||
}
|
||||
|
||||
export namespace Crafter::CppDOMBindings {
|
||||
|
|
@ -228,4 +216,26 @@ export namespace Crafter::CppDOMBindings {
|
|||
CppDOMBindings::fetchHandlers->insert({id, callback});
|
||||
FetchWithBody(url.data(), url.size(), body.data(), body.size(), id);
|
||||
}
|
||||
|
||||
__attribute__((import_module("env"), import_name("getPathName"))) const char* GetPathName();
|
||||
std::string GetPathNameString() {
|
||||
const char* path = GetPathName();
|
||||
return std::string(path);
|
||||
}
|
||||
|
||||
std::int32_t AddPopStateListener(std::function<void(void)> callback) {
|
||||
std::int32_t id = popStateHandlerMaxId++;
|
||||
popStateHandlers->insert({id, callback});
|
||||
AddPopStateListener(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemovePopStateListener(std::int32_t id) {
|
||||
RemovePopStateListener(id);
|
||||
popStateHandlers->erase(id);
|
||||
}
|
||||
|
||||
void PushState(const std::string_view data, const std::string_view title, const std::string_view url) {
|
||||
PushState(data.data(), data.size(), title.data(), title.size(), url.data(), url.size());
|
||||
}
|
||||
}
|
||||
|
|
@ -142,6 +142,10 @@ export namespace Crafter::CppDOMBindings {
|
|||
|
||||
// Value property functions
|
||||
__attribute__((import_module("env"), import_name("getValue"))) const char* GetValue(void* ptr);
|
||||
__attribute__((import_module("env"), import_name("getPathName"))) const char* GetPathName();
|
||||
__attribute__((import_module("env"), import_name("addPopStateListener"))) void AddPopStateListener(int id);
|
||||
__attribute__((import_module("env"), import_name("removePopStateListener"))) void RemovePopStateListener(int id);
|
||||
__attribute__((import_module("env"), import_name("pushState"))) void PushState(const char* data, std::int32_t dataLength, const char* title, std::int32_t titleLength, const char* url, std::int32_t urlLength);
|
||||
__attribute__((import_module("env"), import_name("setValue"))) void SetValue(void* ptr, const char* value, std::int32_t valueLength);
|
||||
void SetValue(void* ptr, const std::string_view value) {
|
||||
SetValue(ptr, value.data(), value.size());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue