gg-wf-scripts 2.5.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/action-engine.d.ts +2 -0
- package/dist/action-engine.js +97 -0
- package/dist/action-engine.js.map +1 -0
- package/dist/actions.d.ts +5 -0
- package/dist/actions.js +2 -0
- package/dist/actions.js.map +1 -0
- package/dist/attrs.d.ts +59 -0
- package/dist/attrs.js +67 -0
- package/dist/attrs.js.map +1 -0
- package/dist/auth.d.ts +6 -0
- package/dist/auth.js +28 -0
- package/dist/auth.js.map +1 -0
- package/dist/bridges.d.ts +1 -0
- package/dist/bridges.js +43 -0
- package/dist/bridges.js.map +1 -0
- package/dist/data-engine.d.ts +2 -0
- package/dist/data-engine.js +153 -0
- package/dist/data-engine.js.map +1 -0
- package/dist/dialog.d.ts +1 -0
- package/dist/dialog.js +93 -0
- package/dist/dialog.js.map +1 -0
- package/dist/dom-observer.d.ts +4 -0
- package/dist/dom-observer.js +47 -0
- package/dist/dom-observer.js.map +1 -0
- package/dist/engine-deps.d.ts +23 -0
- package/dist/engine-deps.js +2 -0
- package/dist/engine-deps.js.map +1 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.js +30 -0
- package/dist/errors.js.map +1 -0
- package/dist/form-action-engine.d.ts +2 -0
- package/dist/form-action-engine.js +173 -0
- package/dist/form-action-engine.js.map +1 -0
- package/dist/form-actions.d.ts +10 -0
- package/dist/form-actions.js +2 -0
- package/dist/form-actions.js.map +1 -0
- package/dist/form-visibility.d.ts +1 -0
- package/dist/form-visibility.js +109 -0
- package/dist/form-visibility.js.map +1 -0
- package/dist/helpers/dom.d.ts +16 -0
- package/dist/helpers/dom.js +39 -0
- package/dist/helpers/dom.js.map +1 -0
- package/dist/helpers/form-field.d.ts +19 -0
- package/dist/helpers/form-field.js +58 -0
- package/dist/helpers/form-field.js.map +1 -0
- package/dist/helpers/path.d.ts +2 -0
- package/dist/helpers/path.js +9 -0
- package/dist/helpers/path.js.map +1 -0
- package/dist/helpers/run-handler.d.ts +26 -0
- package/dist/helpers/run-handler.js +36 -0
- package/dist/helpers/run-handler.js.map +1 -0
- package/dist/helpers/run-with-loading.d.ts +6 -0
- package/dist/helpers/run-with-loading.js +28 -0
- package/dist/helpers/run-with-loading.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/queries.d.ts +1 -0
- package/dist/queries.js +2 -0
- package/dist/queries.js.map +1 -0
- package/dist/query-params.d.ts +19 -0
- package/dist/query-params.js +160 -0
- package/dist/query-params.js.map +1 -0
- package/dist/switch-engine.d.ts +1 -0
- package/dist/switch-engine.js +28 -0
- package/dist/switch-engine.js.map +1 -0
- package/package.json +25 -2
- package/src/action-engine.js +0 -64
- package/src/actions.js +0 -14
- package/src/auth.js +0 -28
- package/src/bridges.js +0 -31
- package/src/data-engine.js +0 -165
- package/src/dialog.js +0 -86
- package/src/form-action-engine.js +0 -149
- package/src/form-actions.js +0 -21
- package/src/form-visibility.js +0 -122
- package/src/helpers/dom.js +0 -35
- package/src/helpers/log.js +0 -34
- package/src/helpers/path.js +0 -4
- package/src/index.js +0 -60
- package/src/queries.js +0 -14
- package/src/query-params.js +0 -144
- package/src/switch-engine.js +0 -22
package/src/index.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { registerQuery } from "./queries.js";
|
|
2
|
-
import { registerAction } from "./actions.js";
|
|
3
|
-
import { registerFormAction } from "./form-actions.js";
|
|
4
|
-
import { setSwitchState, applySwitchState, populateFields } from "./helpers/dom.js";
|
|
5
|
-
import { setQueryParams, removeQueryParams, initQueryParams } from "./query-params.js";
|
|
6
|
-
import { initAuth } from "./auth.js";
|
|
7
|
-
import { initSwitchEngine } from "./switch-engine.js";
|
|
8
|
-
import { initDialog } from "./dialog.js";
|
|
9
|
-
import { initBridges } from "./bridges.js";
|
|
10
|
-
import { initFormVisibility } from "./form-visibility.js";
|
|
11
|
-
import { initDataEngine } from "./data-engine.js";
|
|
12
|
-
import { initActionEngine } from "./action-engine.js";
|
|
13
|
-
import { initFormActionEngine } from "./form-action-engine.js";
|
|
14
|
-
|
|
15
|
-
export { setSwitchState, applySwitchState, populateFields, setQueryParams, removeQueryParams };
|
|
16
|
-
export { getPath } from "./helpers/path.js";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create a gg-scripts app instance.
|
|
20
|
-
*
|
|
21
|
-
* @param {object} [options]
|
|
22
|
-
* @param {object} [options.context] - Arbitrary object passed to every query and action.
|
|
23
|
-
* Put backend clients (Supabase, fetch wrappers, etc.) or anything else your queries need on it.
|
|
24
|
-
* @param {object} [options.auth] - Auth adapter. If omitted, gg-auth/gg-role attrs are never set.
|
|
25
|
-
* @param {() => (string|null) | Promise<string|null>} options.auth.getUser
|
|
26
|
-
* Returns the current user id, or null when signed out.
|
|
27
|
-
* @param {(cb: (userId: string|null) => void) => void} [options.auth.onChange]
|
|
28
|
-
* Subscribe to auth changes. Called with the new user id (or null) whenever it changes.
|
|
29
|
-
* @param {(context: object, userId: string) => Promise<string|null>} [options.auth.roleQuery]
|
|
30
|
-
* Returns the user's role string for gg-role gating. If omitted, gg-role is never set.
|
|
31
|
-
* @param {boolean} [options.debug=false] - When true, every query and action is logged to the
|
|
32
|
-
* console with its trigger/container, data, result, and duration.
|
|
33
|
-
* @returns {{ addQuery: function, addAction: function, start: function }}
|
|
34
|
-
*/
|
|
35
|
-
export function init({ context = {}, auth, debug = false } = {}) {
|
|
36
|
-
return {
|
|
37
|
-
addQuery: registerQuery,
|
|
38
|
-
addAction: registerAction,
|
|
39
|
-
addFormAction: registerFormAction,
|
|
40
|
-
start() {
|
|
41
|
-
function run() {
|
|
42
|
-
if (auth) initAuth(context, auth);
|
|
43
|
-
initSwitchEngine();
|
|
44
|
-
initQueryParams();
|
|
45
|
-
initDialog();
|
|
46
|
-
initBridges();
|
|
47
|
-
initFormVisibility();
|
|
48
|
-
initDataEngine(context, { debug });
|
|
49
|
-
initActionEngine(context, { debug });
|
|
50
|
-
initFormActionEngine(context, { debug });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (document.readyState === "loading") {
|
|
54
|
-
document.addEventListener("DOMContentLoaded", run);
|
|
55
|
-
} else {
|
|
56
|
-
run();
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
}
|
package/src/queries.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const queryRegistry = {};
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Register a data query for use with gg-data, gg-data-form, or gg-data-list.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} id - The query identifier, referenced by gg-data="<id>" in markup.
|
|
7
|
-
* @param {(context: object, params: URLSearchParams) => Promise<object|object[]|null>} fn
|
|
8
|
-
* Receives the context object passed to init() and a URLSearchParams snapshot of the
|
|
9
|
-
* current URL query string. Return a single object (or null) for gg-data/gg-data-form,
|
|
10
|
-
* or an array for gg-data-list.
|
|
11
|
-
*/
|
|
12
|
-
export function registerQuery(id, fn) {
|
|
13
|
-
queryRegistry[id] = fn;
|
|
14
|
-
}
|
package/src/query-params.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
const subscribers = [];
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Snapshot of the current URL query string as a URLSearchParams instance.
|
|
5
|
-
*/
|
|
6
|
-
export function getParams() {
|
|
7
|
-
return new URL(window.location).searchParams;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function onQueryChanged(callback) {
|
|
11
|
-
subscribers.push(callback);
|
|
12
|
-
return () => {
|
|
13
|
-
const idx = subscribers.indexOf(callback);
|
|
14
|
-
if (idx >= 0) subscribers.splice(idx, 1);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function notify(key, value) {
|
|
19
|
-
subscribers.forEach((cb) => cb(key, value));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Set one or more URL query params and notify subscribers.
|
|
24
|
-
*
|
|
25
|
-
* @param {Array<{key: string, value: string}>} params - Key/value pairs to set.
|
|
26
|
-
*/
|
|
27
|
-
export function setQueryParams(params) {
|
|
28
|
-
const url = new URL(window.location);
|
|
29
|
-
params.forEach(({ key, value }) => url.searchParams.set(key, value));
|
|
30
|
-
history.pushState({}, "", url);
|
|
31
|
-
params.forEach(({ key, value }) => notify(key, value));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Remove one or more URL query params and notify subscribers.
|
|
36
|
-
*
|
|
37
|
-
* @param {string[]} keys - Param keys to remove.
|
|
38
|
-
*/
|
|
39
|
-
export function removeQueryParams(keys) {
|
|
40
|
-
const url = new URL(window.location);
|
|
41
|
-
keys.forEach((key) => url.searchParams.delete(key));
|
|
42
|
-
history.pushState({}, "", url);
|
|
43
|
-
keys.forEach((key) => notify(key, null));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ---- click delegation for gg-query-set / gg-query-remove ----
|
|
47
|
-
|
|
48
|
-
function handleQueryClick(target) {
|
|
49
|
-
const setTrigger = target.closest("[gg-query-set]");
|
|
50
|
-
if (setTrigger) {
|
|
51
|
-
const params = setTrigger
|
|
52
|
-
.getAttribute("gg-query-set")
|
|
53
|
-
.split(",")
|
|
54
|
-
.filter(Boolean)
|
|
55
|
-
.map((pair) => {
|
|
56
|
-
const [key, value] = pair.split(":");
|
|
57
|
-
return { key: key?.trim(), value: value?.trim() };
|
|
58
|
-
})
|
|
59
|
-
.filter((p) => p.key && p.value);
|
|
60
|
-
if (params.length) setQueryParams(params);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const removeTrigger = target.closest("[gg-query-remove]");
|
|
65
|
-
if (removeTrigger) {
|
|
66
|
-
const keys = removeTrigger
|
|
67
|
-
.getAttribute("gg-query-remove")
|
|
68
|
-
.split(",")
|
|
69
|
-
.map((k) => k.trim())
|
|
70
|
-
.filter(Boolean);
|
|
71
|
-
if (keys.length) removeQueryParams(keys);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function initQueryParams() {
|
|
77
|
-
document.addEventListener("click", (e) => handleQueryClick(e.target));
|
|
78
|
-
|
|
79
|
-
// Shadow-root click forwarder — shadow DOM swallows bubbling, so anything
|
|
80
|
-
// inside a shadow tree dispatches `gg:shadow:click` with the real target.
|
|
81
|
-
document.addEventListener("gg:shadow:click", (e) =>
|
|
82
|
-
handleQueryClick(e.detail.target),
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
initQueryBindings();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// ---- gg-query-bind: input/textarea/select <-> URL param ----
|
|
89
|
-
|
|
90
|
-
function syncBindInputFromUrl(el) {
|
|
91
|
-
const key = el.getAttribute("gg-query-bind");
|
|
92
|
-
if (!key) return;
|
|
93
|
-
const value = new URL(window.location).searchParams.get(key) ?? "";
|
|
94
|
-
if (el.value !== value) el.value = value;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function setupQueryBindInput(el) {
|
|
98
|
-
const key = el.getAttribute("gg-query-bind");
|
|
99
|
-
if (!key) return;
|
|
100
|
-
const debounceMs = parseInt(el.getAttribute("gg-query-debounce") ?? "0", 10) || 0;
|
|
101
|
-
|
|
102
|
-
syncBindInputFromUrl(el);
|
|
103
|
-
|
|
104
|
-
let timer;
|
|
105
|
-
let suppress = false;
|
|
106
|
-
el.addEventListener("input", () => {
|
|
107
|
-
if (suppress) return;
|
|
108
|
-
clearTimeout(timer);
|
|
109
|
-
const fire = () => {
|
|
110
|
-
const value = el.value;
|
|
111
|
-
if (value === "") {
|
|
112
|
-
removeQueryParams([key]);
|
|
113
|
-
} else {
|
|
114
|
-
setQueryParams([{ key, value }]);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
if (debounceMs > 0) {
|
|
118
|
-
timer = setTimeout(fire, debounceMs);
|
|
119
|
-
} else {
|
|
120
|
-
fire();
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// When the URL changes from elsewhere (back button, programmatic), mirror
|
|
125
|
-
// it into the input without re-firing the input listener.
|
|
126
|
-
onQueryChanged((changedKey, value) => {
|
|
127
|
-
if (changedKey !== key) return;
|
|
128
|
-
const next = value ?? "";
|
|
129
|
-
if (el.value === next) return;
|
|
130
|
-
suppress = true;
|
|
131
|
-
el.value = next;
|
|
132
|
-
suppress = false;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function initQueryBindings() {
|
|
137
|
-
document.querySelectorAll("[gg-query-bind]").forEach(setupQueryBindInput);
|
|
138
|
-
|
|
139
|
-
// Back/forward navigation doesn't fire pushState notifications, so
|
|
140
|
-
// re-sync all bound inputs from the URL on popstate.
|
|
141
|
-
window.addEventListener("popstate", () => {
|
|
142
|
-
document.querySelectorAll("[gg-query-bind]").forEach(syncBindInputFromUrl);
|
|
143
|
-
});
|
|
144
|
-
}
|
package/src/switch-engine.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { applySwitchState } from "./helpers/dom.js";
|
|
2
|
-
|
|
3
|
-
export function initSwitchEngine() {
|
|
4
|
-
// Re-apply whenever gg-switch-state changes on any element.
|
|
5
|
-
new MutationObserver((mutations) => {
|
|
6
|
-
mutations.forEach((m) => {
|
|
7
|
-
if (m.attributeName === "gg-switch-state") {
|
|
8
|
-
applySwitchState(m.target);
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
}).observe(document.body, {
|
|
12
|
-
attributes: true,
|
|
13
|
-
attributeFilter: ["gg-switch-state"],
|
|
14
|
-
subtree: true,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// Apply initial state for any elements that already have gg-switch-state
|
|
18
|
-
// set at load time, so we don't flash all children before the first mutation.
|
|
19
|
-
document
|
|
20
|
-
.querySelectorAll("[gg-switch-state]")
|
|
21
|
-
.forEach(applySwitchState);
|
|
22
|
-
}
|