gg-wf-scripts 4.0.0 → 4.1.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 +15 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,6 +110,20 @@ if (form.__ggRecord) hydrate(form.__ggRecord);
|
|
|
110
110
|
|
|
111
111
|
The event bubbles, so each form/container's events are scoped to that subtree — listeners attached to one form never fire for another. From inside a shadow root, walk out via `getRootNode().host` before calling `closest("form")`.
|
|
112
112
|
|
|
113
|
+
#### Calling queries / actions from custom code
|
|
114
|
+
|
|
115
|
+
`init()` sets `window.ggApp` by default and dispatches a `gg-app-ready` CustomEvent on `document` (with `detail.app`). Components can call any registered handler imperatively — useful for typeahead/combobox patterns that don't fit the declarative `gg-data*` model:
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
const app = window.ggApp; // or await `gg-app-ready`
|
|
119
|
+
const results = await app.queries.search_schools(
|
|
120
|
+
app.context,
|
|
121
|
+
new URLSearchParams({ q: "acme" }),
|
|
122
|
+
);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Set `expose: false` on `init()` if you'd rather wire the reference yourself.
|
|
126
|
+
|
|
113
127
|
#### Re-running on URL changes
|
|
114
128
|
|
|
115
129
|
Add `gg-data-on` to re-run a query when specific URL params change:
|
|
@@ -367,6 +381,7 @@ Returns an app instance with `addQuery`, `addAction`, and `start` methods.
|
|
|
367
381
|
| `context` | `object` | No | Arbitrary object passed to every query and action. Put backend clients or anything else your handlers need on it. Defaults to `{}`. |
|
|
368
382
|
| `auth` | `object` | No | Auth adapter (see below). If omitted, `gg-auth`/`gg-role` attrs are never set. |
|
|
369
383
|
| `debug` | `boolean` | No | When `true`, every query and action is logged to the console (trigger/container, data, result, duration). Defaults to `false`. |
|
|
384
|
+
| `expose` | `boolean` | No | When `true` (default), the App is set as `window.ggApp` and a `gg-app-ready` CustomEvent is dispatched on `document` so React/web-component islands can pick it up. Set to `false` for tests, multiple instances, or non-browser hosts. |
|
|
370
385
|
|
|
371
386
|
### Auth adapter
|
|
372
387
|
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,12 @@ export type InitOptions<TContext = unknown> = {
|
|
|
26
26
|
* trigger/container, data, result, and duration.
|
|
27
27
|
*/
|
|
28
28
|
debug?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* When true (default), the App is exposed as `window.ggApp` and a
|
|
31
|
+
* `gg-app-ready` CustomEvent is dispatched on `document`. Set to `false`
|
|
32
|
+
* to opt out — useful for tests, multiple instances, or non-browser hosts.
|
|
33
|
+
*/
|
|
34
|
+
expose?: boolean;
|
|
29
35
|
};
|
|
30
36
|
export type App<TContext = unknown> = {
|
|
31
37
|
context: TContext;
|
|
@@ -66,4 +72,4 @@ export type App<TContext = unknown> = {
|
|
|
66
72
|
/**
|
|
67
73
|
* Create a gg-scripts app instance.
|
|
68
74
|
*/
|
|
69
|
-
export declare function init<TContext = unknown>({ context, auth, debug }?: InitOptions<TContext>): App<TContext>;
|
|
75
|
+
export declare function init<TContext = unknown>({ context, auth, debug, expose, }?: InitOptions<TContext>): App<TContext>;
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export { getPath } from "./helpers/path.js";
|
|
|
14
14
|
/**
|
|
15
15
|
* Create a gg-scripts app instance.
|
|
16
16
|
*/
|
|
17
|
-
export function init({ context = {}, auth, debug = false } = {}) {
|
|
17
|
+
export function init({ context = {}, auth, debug = false, expose = true, } = {}) {
|
|
18
18
|
const queries = {};
|
|
19
19
|
const actions = {};
|
|
20
20
|
const formActions = {};
|
|
@@ -67,6 +67,13 @@ export function init({ context = {}, auth, debug = false } = {}) {
|
|
|
67
67
|
cleanups = [];
|
|
68
68
|
},
|
|
69
69
|
};
|
|
70
|
+
if (expose && typeof window !== "undefined") {
|
|
71
|
+
if (window.ggApp) {
|
|
72
|
+
console.warn("[gg] window.ggApp is being replaced by a new init() call");
|
|
73
|
+
}
|
|
74
|
+
window.ggApp = app;
|
|
75
|
+
document.dispatchEvent(new CustomEvent("gg-app-ready", { detail: { app } }));
|
|
76
|
+
}
|
|
70
77
|
return app;
|
|
71
78
|
}
|
|
72
79
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAoB,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAwC,MAAM,aAAa,CAAC;AAEnF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAoB,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,gBAAgB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