Skip to content

Commit

Permalink
0.0.136
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansglazunov committed Oct 6, 2024
1 parent 31b1e2b commit 0c04007
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
32 changes: 17 additions & 15 deletions imports/go.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,27 @@ export const GoCustomContext = createContext<any>({});
export function GoCustomProvider({ value, children = null }) {
return <GoCustomContext.Provider value={value}>{children}</GoCustomContext.Provider>;
}
export const useGoCustom = function useGoCustom(go) {
const custom = useContext(GoCustomContext);
if (go && !go._custom) {
for (let c in custom) {
go[c] = custom[c];
}
go._custom = true;
}
}

export function useGoCore(context?: GoContextI) { return useContext(context || GoContext); }
export function useGoCore(context?: GoContextI) {
const go = useContext(context || GoContext) || fillGo();
useGoCustom(go);
return go;
}

export const ValueContext = createContext<any>(undefined);

let _i = 0;
let _p = 0;

export const GoEditorContext = createContext<any>(undefined);
export const GoEditorProvider = memo(function GoEditorProvider({ Editor, children }: { Editor: any; children: any }) {
return <GoEditorContext.Provider value={Editor}>{children}</GoEditorContext.Provider>
});

export const selfReturnGo = () => selfReturnGo;

export function fillGo(go: any = selfReturnGo) {
Expand Down Expand Up @@ -229,7 +237,6 @@ export const GoProvider = memo(function GoProvider({

hotkeys?: boolean;
}) {
const Editor = useContext(GoEditorContext);
const deep = useDeep();
const __p = useMemo(() => { return _p++; }, []);
const __parentGo: GoI = useGoCore(context);
Expand All @@ -249,8 +256,6 @@ export const GoProvider = memo(function GoProvider({
const pgoRef = useRef<any>();
const __actualGoRef = useRef<any>(_parentGo);

const custom = useContext(GoCustomContext) || {};

const { go, parentGo }: { go: GoI, parentGo: GoI } = useMemo(() => {
const _go = (linkId ? function go(path?: PathI) { return _go._go(path); } : _parentGo) as GoI;
if (linkId) {
Expand Down Expand Up @@ -297,8 +302,7 @@ export const GoProvider = memo(function GoProvider({
go.go = linkId ? parentGo : parentGo?.go;
go._go = _go;
go.current = go?.children?.[value];

go.Editor = Editor;

go.loader = _loader;

fillGo(go);
Expand All @@ -309,16 +313,14 @@ export const GoProvider = memo(function GoProvider({
go.__go = parentGo;
go.__actualGoRef = (linkId ? __actualGoRef : parentGo?.__actualGoRef) || __actualGoRef;

for (let c in custom) {
go[c] = custom[c];
}

go.componentTemplate = componentTemplate;
go.hookTemplate = hookTemplate;

// console.log('go fields', 'provider', __p, deep.nameLocal(linkId), go === parentGo ? `parent ${parentGo.__p}` : 'new', go._i, deep.nameLocal(go.linkId), deep.nameLocal(go.value));
}, [go, value, deep]);

useGoCustom(go);

const _set = useCallback((_value, ...args) => {
go.value = _value;
if (go.children?.[go.value]) {
Expand Down
8 changes: 4 additions & 4 deletions imports/hooks.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

import { useTheme } from '@chakra-ui/react';
import { useDeep, Id } from "@deep-foundation/deeplinks";
import { Id, useDeep } from "@deep-foundation/deeplinks";

import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
import { GoEditorProvider, useGoCore } from './go.js';
import { useGoCore } from './go.js';

export function Packages() {
const deep = useDeep();
Expand Down Expand Up @@ -107,9 +107,9 @@ export function PreloadProvider({
children?: any;
}) {
const deep = useDeep();
return <GoEditorProvider Editor={Editor}>
return <>
{deep ? [<PreloadProviderCore key={deep.linkId} preloaded={preloaded} children={children}/>] : children}
</GoEditorProvider>
</>
}

export function useSymbol() {
Expand Down
7 changes: 1 addition & 6 deletions imports/preload.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { generateApolloClient } from '@deep-foundation/hasura/client.js';
import { DeepClient, toPlain, useDeep } from '@deep-foundation/deeplinks';
import axios from 'axios';
import type { NextApiRequest, NextApiResponse } from 'next';
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';

let _path, _ssl = true;
Expand Down Expand Up @@ -194,17 +193,13 @@ export function PreloadProviderCore({

export function PreloadProvider({
preloaded = {},
Editor,
children = null,
}: {
preloaded?: { packages?: any[]; handlers?: any[]; };
Editor: any;
children?: any;
}) {
const deep = useDeep();
// return <GoEditorProvider Editor={Editor}>
return <>
{deep ? [<PreloadProviderCore key={deep.linkId} preloaded={preloaded} children={children}/>] : children};
</>;
{/* </GoEditorProvider> */}
}
4 changes: 2 additions & 2 deletions imports/react-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ export function ReactHandlerEditor({
<ModalContent maxW='90%' maxH='90%' h='100%' opacity={0.9}>
<ModalBody p='1em'>
<Flex direction={'column'} h='100%'>
{/* <Alert status={'info'}>
<Alert status={'info'}>
<AlertIcon />
<AlertTitle>Editor:</AlertTitle>
</Alert> */}
</Alert>
<Box>{handlers.map(f => <React.Fragment key={f.handler_id}>
<Box display='inline-flex' p='0.2em' h='3em'>{deep.minilinks.byId[f?.handler_id]?.id} {deep.minilinks.byId[f?.handler_id]?.name}</Box>
{!!f.src && <Button h='3em' variant={file === f.src ? 'active' : null} onClick={() => setFile(f.src)}>src</Button>}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deep-foundation/perception-imports",
"version": "0.0.135",
"version": "0.0.136",
"license": "Unlicense",
"type": "module",
"main": "import.js",
Expand Down

0 comments on commit 0c04007

Please sign in to comment.