Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add on-event behavior to allowed list for navigation behaviors #3

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f398959
chore(cleanup) - improving url logic (#612)
hgray-instawork Jul 28, 2023
9a8f7d6
fix(navigator) - improved handling of nested navigators (#615)
hgray-instawork Aug 1, 2023
1a916e0
feature(deep link) - add support for merging a received document with…
hgray-instawork Aug 2, 2023
ecc28d8
chore (navigation) - Cleanup of navigator helpers (#622)
hgray-instawork Aug 3, 2023
ee258e7
feature(selection) - Track the current selection state of each nav-ro…
hgray-instawork Aug 4, 2023
4ea3a44
chore(nav-routes) - Update to support adding all defined routes to na…
hgray-instawork Aug 4, 2023
9174827
fix(hvroute) - Prioritize the source of data for a route (#625)
hgray-instawork Aug 4, 2023
7cfda68
chore(modal) - Change iOS presentation to use fullscreen (#626)
hgray-instawork Aug 8, 2023
d8844d3
fix(state) - override the state.doc (#632)
hgray-instawork Aug 8, 2023
a0b27c0
chore(cleanup) - performance improvements (#637)
hgray-instawork Aug 9, 2023
b204efb
chore(refactor) - small improvements to navigator code organization (…
hgray-instawork Aug 9, 2023
06beb94
chore(modal) - add a stack navigator to modals (#641)
hgray-instawork Aug 9, 2023
0a728dd
chore(dynamic) - refactor 'dynamic' to 'card' (#642)
hgray-instawork Aug 10, 2023
2f34bec
chore(destructuring) - remove prop and component destructuring (#643)
hgray-instawork Aug 14, 2023
98a1db5
chore(dom) - reflect navigation state in dom (#651)
hgray-instawork Aug 14, 2023
84be399
chore(cleanup) - improved setup for tab navigator options (#656)
hgray-instawork Aug 17, 2023
9ae8020
chore(cleanup) - passing props (#657)
hgray-instawork Aug 22, 2023
31af54b
chore(navigation) - cleanup attribute retrieval (#686)
hgray-instawork Sep 20, 2023
67f38c0
chore (context) - merge document contexts (#690)
hgray-instawork Sep 26, 2023
af14f07
feature(deep link) - provide deep link support for navigation (#691)
hgray-instawork Sep 27, 2023
0d35642
chore(bug) - fix navigation (#698)
hgray-instawork Oct 2, 2023
3408df1
Merge branch 'master' into hardin/navigation-integration
hgray-instawork Oct 12, 2023
0e4ac0d
chore(navigation): cleanup after merging master (#722)
hgray-instawork Oct 12, 2023
c156d5c
Merge branch 'master' into hardin/navigation-integration
hgray-instawork Oct 17, 2023
077e3a5
chore(behaviors): centralize behavior trigger code (#726)
hgray-instawork Oct 17, 2023
bcee080
chore(on update): lift onUpdate and its methods from hv-screen to hv-…
hgray-instawork Oct 19, 2023
638146e
chore(document): account for possible null doc in state (#728)
hgray-instawork Oct 19, 2023
5667a5f
chore(hvroute): hvroute as an onUpdate provider for navigator (#729)
hgray-instawork Oct 23, 2023
f3e25c0
feat(navigation behaviors): implementation of behaviors in navigators…
hgray-instawork Oct 23, 2023
f5110f4
fix: deep link urls are not triggering navigation events (#733)
hgray-instawork Nov 1, 2023
676098c
Allow on-event behaviors in navigation behavior array
hgray-instawork Nov 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions schema/core.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,11 @@
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" ref="hv:nav-route" />
<xs:element minOccurs="0" maxOccurs="unbounded" ref="hv:behavior" />
</xs:sequence>
<xs:attribute name="id" use="required" type="hv:ID" />
<xs:attribute name="type" use="required" type="hv:navigator-type" />
<xs:attribute name="merge" type="xs:boolean" />
</xs:complexType>
</xs:element>

Expand All @@ -1249,6 +1251,7 @@
<xs:attribute name="id" use="required" type="hv:ID" />
<xs:attribute name="href" use="required" type="xs:string" />
<xs:attribute name="selected" type="xs:boolean" />
<xs:attribute name="modal" type="xs:boolean" />
</xs:complexType>
</xs:element>

Expand Down
21 changes: 12 additions & 9 deletions src/behaviors/hv-hide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default {
);

const hideElement = () => {
const doc: Document = getRoot();
const targetElement: Element | null | undefined = doc.getElementById(
const doc: Document | null = getRoot();
const targetElement: Element | null | undefined = doc?.getElementById(
targetId,
);
if (!targetElement) {
Expand Down Expand Up @@ -65,13 +65,16 @@ export default {
hideElement();
} else {
// If there's a delay, first trigger the indicators before the hide
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
getRoot(),
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
const doc: Document | null = getRoot();
if (doc) {
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
doc,
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
}
// Wait for the delay then hide the target.
later(delay).then(hideElement).catch(hideElement);
}
Expand Down
21 changes: 12 additions & 9 deletions src/behaviors/hv-select-all/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default {
);

const selectAll = () => {
const doc: Document = getRoot();
const targetElement: Element | null | undefined = doc.getElementById(
const doc: Document | null = getRoot();
const targetElement: Element | null | undefined = doc?.getElementById(
targetId,
);
if (!targetElement) {
Expand Down Expand Up @@ -66,13 +66,16 @@ export default {
selectAll();
} else {
// If there's a delay, first trigger the indicators before the select-all.
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
getRoot(),
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
const doc: Document | null = getRoot();
if (doc) {
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
doc,
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
}
// Wait for the delay then select-all the target.
later(delay).then(selectAll).catch(selectAll);
}
Expand Down
21 changes: 12 additions & 9 deletions src/behaviors/hv-set-value/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export default {
);

const setValue = () => {
const doc: Document = getRoot();
const targetElement: Element | null | undefined = doc.getElementById(
const doc: Document | null = getRoot();
const targetElement: Element | null | undefined = doc?.getElementById(
targetId,
);
if (!targetElement) {
Expand Down Expand Up @@ -68,13 +68,16 @@ export default {
setValue();
} else {
// If there's a delay, first trigger the indicators before the show.
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
getRoot(),
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
const doc: Document | null = getRoot();
if (doc) {
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
doc,
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
}
// Wait for the delay then show the target.
later(delay).then(setValue).catch(setValue);
}
Expand Down
21 changes: 12 additions & 9 deletions src/behaviors/hv-show/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default {
);

const showElement = () => {
const doc: Document = getRoot();
const targetElement: Element | null | undefined = doc.getElementById(
const doc: Document | null = getRoot();
const targetElement: Element | null | undefined = doc?.getElementById(
targetId,
);
if (!targetElement) {
Expand Down Expand Up @@ -65,13 +65,16 @@ export default {
showElement();
} else {
// If there's a delay, first trigger the indicators before the show.
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
getRoot(),
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
const doc: Document | null = getRoot();
if (doc) {
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
doc,
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
}
// Wait for the delay then show the target.
later(delay).then(showElement).catch(showElement);
}
Expand Down
21 changes: 12 additions & 9 deletions src/behaviors/hv-toggle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default {
);

const toggleElement = () => {
const doc: Document = getRoot();
const targetElement: Element | null | undefined = doc.getElementById(
const doc: Document | null = getRoot();
const targetElement: Element | null | undefined = doc?.getElementById(
targetId,
);
if (!targetElement) {
Expand Down Expand Up @@ -68,13 +68,16 @@ export default {
toggleElement();
} else {
// If there's a delay, first trigger the indicators before the toggle.
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
getRoot(),
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
const doc: Document | null = getRoot();
if (doc) {
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
doc,
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
}
// Wait for the delay then toggle the target.
later(delay).then(toggleElement).catch(toggleElement);
}
Expand Down
21 changes: 12 additions & 9 deletions src/behaviors/hv-unselect-all/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default {
);

const unselectAll = () => {
const doc: Document = getRoot();
const targetElement: Element | null | undefined = doc.getElementById(
const doc: Document | null = getRoot();
const targetElement: Element | null | undefined = doc?.getElementById(
targetId,
);
if (!targetElement) {
Expand Down Expand Up @@ -66,13 +66,16 @@ export default {
unselectAll();
} else {
// If there's a delay, first trigger the indicators before the unselect-all.
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
getRoot(),
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
const doc: Document | null = getRoot();
if (doc) {
const newRoot = Behaviors.setIndicatorsBeforeLoad(
showIndicatorIds,
hideIndicatorIds,
doc,
);
// Update the DOM to reflect the new state of the indicators.
updateRoot(newRoot);
}
// Wait for the delay then unselect-all the target.
later(delay).then(unselectAll).catch(unselectAll);
}
Expand Down
2 changes: 2 additions & 0 deletions src/behaviors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ export {
setIndicatorsBeforeLoad,
performUpdate,
setIndicatorsAfterLoad,
isOncePreviouslyApplied,
setRanOnce,
} from 'hyperview/src/services/behaviors';
9 changes: 8 additions & 1 deletion src/contexts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import type { ComponentType } from 'react';
import type { HvComponentOnUpdate } from 'hyperview/src/types';
import React from 'react';
import type { RefreshControlProps } from 'react-native';

Expand All @@ -24,5 +25,11 @@ export const RefreshControlComponentContext = React.createContext<
>(undefined);

export const DocContext = React.createContext<{
getDoc: () => Document;
getDoc: () => Document | undefined;
setDoc?: (doc: Document) => void;
} | null>(null);

export const OnUpdateContext = React.createContext<{
onUpdate: HvComponentOnUpdate;
// eslint-disable-next-line @typescript-eslint/no-empty-function
}>({ onUpdate: () => {} });
8 changes: 7 additions & 1 deletion src/contexts/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* LICENSE file in the root directory of this source tree.
*
*/
import type { Fetch, HvBehavior, HvComponent } from 'hyperview/src/types';
import type {
Fetch,
HvBehavior,
HvComponent,
HvComponentOnUpdate,
} from 'hyperview/src/types';
lizard-boy marked this conversation as resolved.
Show resolved Hide resolved

import React, { ComponentType, ReactNode } from 'react';

Expand All @@ -18,6 +23,7 @@ export type NavigationContextProps = {
onError?: (error: Error) => void;
onParseAfter?: (url: string) => void;
onParseBefore?: (url: string) => void;
onUpdate: HvComponentOnUpdate;
url?: string;
behaviors?: HvBehavior[];
components?: HvComponent[];
Expand Down
32 changes: 0 additions & 32 deletions src/contexts/navigator-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,20 @@
import React, { createContext, useState } from 'react';

export type NavigatorMapContextProps = {
setRoute: (key: string, route: string) => void;
getRoute: (key: string) => string | undefined;
setElement: (key: string, element: Element) => void;
getElement: (key: string) => Element | undefined;
setPreload: (key: number, element: Element) => void;
getPreload: (key: number) => Element | undefined;
initialRouteName?: string;
};

/**
* Context used to store runtime information about the navigator and urls
* Each navigator creates its own context
* - routeMap: Urls defined in <nav-route> elements are stored in the routeMap by their key
* - elementMap: Contains element sub-navigators defined in a <nav-route> element
* - initialRouteName: The name of the first route to render
* - preloadMap: A map of preload elements by their id
*/
export const NavigatorMapContext = createContext<NavigatorMapContextProps>({
getElement: () => undefined,
getPreload: () => undefined,
getRoute: () => '',
setElement: () => undefined,
setPreload: () => undefined,
setRoute: () => undefined,
});

type Props = { children: React.ReactNode };
Expand All @@ -42,26 +32,8 @@ type Props = { children: React.ReactNode };
* store runtime information about the navigator and urls.
*/
export function NavigatorMapProvider(props: Props) {
const [routeMap] = useState<Map<string, string>>(new Map());
const [elementMap] = useState<Map<string, Element>>(new Map());
const [preloadMap] = useState<Map<number, Element>>(new Map());

const setRoute = (key: string, route: string) => {
routeMap.set(key, route);
};

const getRoute = (key: string): string | undefined => {
return routeMap.get(key);
};

const setElement = (key: string, element: Element) => {
elementMap.set(key, element);
};

const getElement = (key: string): Element | undefined => {
return elementMap.get(key);
};

const setPreload = (key: number, element: Element) => {
preloadMap.set(key, element);
};
Expand All @@ -73,12 +45,8 @@ export function NavigatorMapProvider(props: Props) {
return (
<NavigatorMapContext.Provider
value={{
getElement,
getPreload,
getRoute,
setElement,
setPreload,
setRoute,
}}
>
{props.children}
Expand Down
Loading