@glyphjs/runtime 0.1.0 → 0.2.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/dist/index.cjs +41 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -4
- package/dist/index.d.ts +21 -4
- package/dist/index.js +41 -8
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -400,11 +400,13 @@ var RuntimeContext = react.createContext(null);
|
|
|
400
400
|
function RuntimeProvider({
|
|
401
401
|
registry,
|
|
402
402
|
references,
|
|
403
|
+
documentId,
|
|
403
404
|
theme,
|
|
404
405
|
className,
|
|
405
406
|
style: consumerStyle,
|
|
406
407
|
onDiagnostic,
|
|
407
408
|
onNavigate,
|
|
409
|
+
onInteraction,
|
|
408
410
|
children
|
|
409
411
|
}) {
|
|
410
412
|
const resolvedThemeObject = react.useMemo(() => resolveTheme(theme), [theme]);
|
|
@@ -420,11 +422,13 @@ function RuntimeProvider({
|
|
|
420
422
|
() => ({
|
|
421
423
|
registry,
|
|
422
424
|
references,
|
|
425
|
+
documentId,
|
|
423
426
|
theme: resolvedTheme,
|
|
424
427
|
onDiagnostic: onDiagnostic ?? noop,
|
|
425
|
-
onNavigate: onNavigate ?? noop
|
|
428
|
+
onNavigate: onNavigate ?? noop,
|
|
429
|
+
onInteraction
|
|
426
430
|
}),
|
|
427
|
-
[registry, references, resolvedTheme, onDiagnostic, onNavigate]
|
|
431
|
+
[registry, references, documentId, resolvedTheme, onDiagnostic, onNavigate, onInteraction]
|
|
428
432
|
);
|
|
429
433
|
const style = react.useMemo(
|
|
430
434
|
() => ({ ...resolvedThemeObject.variables, ...consumerStyle }),
|
|
@@ -795,7 +799,7 @@ var builtInRenderers = {
|
|
|
795
799
|
};
|
|
796
800
|
|
|
797
801
|
// src/plugins/resolve-props.ts
|
|
798
|
-
function resolveComponentProps(block, definition, references, onNavigate, themeContext, layoutHints, containerContext) {
|
|
802
|
+
function resolveComponentProps(block, definition, references, onNavigate, themeContext, layoutHints, containerContext, onInteraction) {
|
|
799
803
|
const parseResult = definition.schema.safeParse(block.data);
|
|
800
804
|
const data = parseResult.success ? parseResult.data : (() => {
|
|
801
805
|
const err = parseResult.error;
|
|
@@ -825,7 +829,7 @@ function resolveComponentProps(block, definition, references, onNavigate, themeC
|
|
|
825
829
|
}
|
|
826
830
|
}
|
|
827
831
|
}
|
|
828
|
-
|
|
832
|
+
const props = {
|
|
829
833
|
data,
|
|
830
834
|
block,
|
|
831
835
|
outgoingRefs,
|
|
@@ -835,6 +839,10 @@ function resolveComponentProps(block, definition, references, onNavigate, themeC
|
|
|
835
839
|
layout: layoutHints,
|
|
836
840
|
container: containerContext
|
|
837
841
|
};
|
|
842
|
+
if (onInteraction) {
|
|
843
|
+
props.onInteraction = onInteraction;
|
|
844
|
+
}
|
|
845
|
+
return props;
|
|
838
846
|
}
|
|
839
847
|
var defaultConfig = {
|
|
840
848
|
enabled: true,
|
|
@@ -1024,7 +1032,7 @@ function ReferenceIndicator({
|
|
|
1024
1032
|
);
|
|
1025
1033
|
}
|
|
1026
1034
|
function BlockDispatch({ block, layout, container }) {
|
|
1027
|
-
const { registry, references, theme, onNavigate } = useRuntime();
|
|
1035
|
+
const { registry, references, theme, documentId, onNavigate, onInteraction } = useRuntime();
|
|
1028
1036
|
const { incomingRefs, outgoingRefs } = useReferences(block.id);
|
|
1029
1037
|
const hasRefs = incomingRefs.length > 0 || outgoingRefs.length > 0;
|
|
1030
1038
|
if (block.type.startsWith("ui:")) {
|
|
@@ -1040,6 +1048,9 @@ function BlockDispatch({ block, layout, container }) {
|
|
|
1040
1048
|
}
|
|
1041
1049
|
}
|
|
1042
1050
|
}
|
|
1051
|
+
const handleInteraction = onInteraction && block.metadata?.interactive === true ? (event) => {
|
|
1052
|
+
onInteraction({ ...event, documentId });
|
|
1053
|
+
} : void 0;
|
|
1043
1054
|
let content;
|
|
1044
1055
|
const overrideDef = registry.getOverride(block.type);
|
|
1045
1056
|
if (overrideDef) {
|
|
@@ -1058,7 +1069,8 @@ function BlockDispatch({ block, layout, container }) {
|
|
|
1058
1069
|
handleNavigate,
|
|
1059
1070
|
theme,
|
|
1060
1071
|
layout,
|
|
1061
|
-
container
|
|
1072
|
+
container,
|
|
1073
|
+
handleInteraction
|
|
1062
1074
|
);
|
|
1063
1075
|
const Renderer = definition.render;
|
|
1064
1076
|
content = /* @__PURE__ */ jsxRuntime.jsx(Renderer, { ...props });
|
|
@@ -1650,7 +1662,7 @@ function createGlyphRuntime(config) {
|
|
|
1650
1662
|
setThemeState(currentTheme);
|
|
1651
1663
|
setVersion(registryVersion);
|
|
1652
1664
|
}, []);
|
|
1653
|
-
react.
|
|
1665
|
+
react.useEffect(() => {
|
|
1654
1666
|
listeners.add(forceUpdate);
|
|
1655
1667
|
return () => {
|
|
1656
1668
|
listeners.delete(forceUpdate);
|
|
@@ -1661,9 +1673,11 @@ function createGlyphRuntime(config) {
|
|
|
1661
1673
|
{
|
|
1662
1674
|
registry,
|
|
1663
1675
|
references: ir.references,
|
|
1676
|
+
documentId: ir.id,
|
|
1664
1677
|
theme,
|
|
1665
1678
|
onDiagnostic: config.onDiagnostic,
|
|
1666
1679
|
onNavigate: config.onNavigate,
|
|
1680
|
+
onInteraction: config.onInteraction,
|
|
1667
1681
|
children: /* @__PURE__ */ jsxRuntime.jsx(GlyphDocument, { ir, className, animation: config.animation })
|
|
1668
1682
|
}
|
|
1669
1683
|
);
|
|
@@ -1715,6 +1729,25 @@ function SSRPlaceholder({
|
|
|
1715
1729
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
1716
1730
|
}
|
|
1717
1731
|
|
|
1732
|
+
// src/debounce.ts
|
|
1733
|
+
function debounceInteractions(callback, delay = 300) {
|
|
1734
|
+
const timers = /* @__PURE__ */ new Map();
|
|
1735
|
+
return (event) => {
|
|
1736
|
+
const key = `${event.blockId}:${event.kind}`;
|
|
1737
|
+
const existing = timers.get(key);
|
|
1738
|
+
if (existing !== void 0) {
|
|
1739
|
+
clearTimeout(existing);
|
|
1740
|
+
}
|
|
1741
|
+
timers.set(
|
|
1742
|
+
key,
|
|
1743
|
+
setTimeout(() => {
|
|
1744
|
+
timers.delete(key);
|
|
1745
|
+
callback(event);
|
|
1746
|
+
}, delay)
|
|
1747
|
+
);
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1718
1751
|
exports.AnimationContext = AnimationContext;
|
|
1719
1752
|
exports.AnimationProvider = AnimationProvider;
|
|
1720
1753
|
exports.BlockDiagnosticIndicator = BlockDiagnosticIndicator;
|
|
@@ -1747,6 +1780,7 @@ exports.builtInRenderers = builtInRenderers;
|
|
|
1747
1780
|
exports.createGlyphRuntime = createGlyphRuntime;
|
|
1748
1781
|
exports.createResolveVar = createResolveVar;
|
|
1749
1782
|
exports.darkTheme = darkTheme;
|
|
1783
|
+
exports.debounceInteractions = debounceInteractions;
|
|
1750
1784
|
exports.isDarkTheme = isDarkTheme;
|
|
1751
1785
|
exports.lightTheme = lightTheme;
|
|
1752
1786
|
exports.mergeThemeDefaults = mergeThemeDefaults;
|