@zenflux/react-commander 0.0.1-dev → 0.0.2
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/package.json +1 -1
- package/src/_internal/core.ts +3 -3
- package/src/_internal/definitions.ts +2 -2
- package/src/command-base.ts +1 -1
- package/src/commands-manager.ts +3 -3
- package/src/definitions.ts +2 -2
- package/src/hooks/index.ts +8 -8
- package/src/hooks/use-child-command/use-child-command-hook.ts +3 -3
- package/src/hooks/use-child-command/use-child-command-runner.ts +2 -2
- package/src/hooks/use-command/use-command-hook.ts +2 -2
- package/src/hooks/use-command/use-command-runner.ts +2 -2
- package/src/hooks/use-command/use-command-state.ts +4 -4
- package/src/hooks/use-command/use-command.ts +5 -5
- package/src/hooks/use-component/use-component-with-ref.ts +3 -3
- package/src/hooks/use-component/use-component.ts +5 -5
- package/src/hooks/utils.ts +5 -5
- package/src/query/query-component.tsx +1 -1
- package/src/with-commands.tsx +5 -5
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/package.json",
|
|
3
3
|
"name": "@zenflux/react-commander",
|
|
4
4
|
"author": "Leonid Vinikov <leonidvinikov@gmail.com> (https://github.com/iNewLegend)",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.2",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "src/index.ts",
|
|
8
8
|
"files": [
|
package/src/_internal/core.ts
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
REGISTER_INTERNAL_SYMBOL,
|
|
6
6
|
SET_TO_CONTEXT_SYMBOL,
|
|
7
7
|
UNREGISTER_INTERNAL_SYMBOL
|
|
8
|
-
} from "./constants
|
|
8
|
+
} from "./constants";
|
|
9
9
|
|
|
10
|
-
import type { DCoreContext, DCoreInterface, DCoreRegisterArgs } from "./definitions
|
|
10
|
+
import type { DCoreContext, DCoreInterface, DCoreRegisterArgs } from "./definitions";
|
|
11
11
|
|
|
12
12
|
import type { DCommandSingleComponentContext } from "@zenflux/react-commander/definitions";
|
|
13
13
|
|
|
@@ -183,7 +183,7 @@ class Core implements DCoreInterface {
|
|
|
183
183
|
|
|
184
184
|
const core: DCoreInterface = new Core();
|
|
185
185
|
|
|
186
|
-
if (
|
|
186
|
+
if ( /* from vite */ import.meta.env.DEV ) {
|
|
187
187
|
if ( ( window as any ).__DEBUG__ ) {
|
|
188
188
|
core.__devDebug = ( ... args: any[] ) => {
|
|
189
189
|
console.log( ... args );
|
|
@@ -6,11 +6,11 @@ import type {
|
|
|
6
6
|
REGISTER_INTERNAL_SYMBOL,
|
|
7
7
|
SET_TO_CONTEXT_SYMBOL,
|
|
8
8
|
UNREGISTER_INTERNAL_SYMBOL
|
|
9
|
-
} from "./constants
|
|
9
|
+
} from "./constants";
|
|
10
10
|
|
|
11
11
|
import type { DCommandSingleComponentContext } from "@zenflux/react-commander/definitions";
|
|
12
12
|
|
|
13
|
-
import type
|
|
13
|
+
import type EventEmitter from "eventemitter3";
|
|
14
14
|
|
|
15
15
|
export type DCoreContext = {
|
|
16
16
|
[componentNameUnique: string]: DCommandSingleComponentContext;
|
package/src/command-base.ts
CHANGED
package/src/commands-manager.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
import { GET_INTERNAL_SYMBOL } from "./_internal/constants
|
|
2
|
+
import { GET_INTERNAL_SYMBOL } from "./_internal/constants";
|
|
3
3
|
|
|
4
|
-
import core from "./_internal/core.
|
|
4
|
+
import core from "./_internal/core.ts";
|
|
5
5
|
|
|
6
6
|
import type { CommandBase } from "@zenflux/react-commander/command-base";
|
|
7
7
|
|
|
@@ -349,7 +349,7 @@ class CommandsManager {
|
|
|
349
349
|
|
|
350
350
|
export const commands = new CommandsManager();
|
|
351
351
|
|
|
352
|
-
if (
|
|
352
|
+
if ( import.meta.env.DEV ) {
|
|
353
353
|
( window as any ).$$commands = commands;
|
|
354
354
|
( window as any ).$$dev = () => commands.devShowComponents();
|
|
355
355
|
}
|
package/src/definitions.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
2
|
|
|
3
|
-
import type
|
|
3
|
+
import type EventEmitter from "eventemitter3";
|
|
4
4
|
|
|
5
5
|
import type { CommandBase } from "@zenflux/react-commander/command-base";
|
|
6
6
|
|
|
@@ -25,8 +25,8 @@ import type { CommandBase } from "@zenflux/react-commander/command-base";
|
|
|
25
25
|
export interface DCommandFunctionComponent<TProps = any, TState = undefined> extends React.FC<TProps> {
|
|
26
26
|
( props: TProps, state?: TState ): React.ReactNode;
|
|
27
27
|
|
|
28
|
+
// Those methods always implemented "under the hood"
|
|
28
29
|
getName?(): string;
|
|
29
|
-
displayName?: string;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
export { useCommand } from "./use-command/use-command
|
|
3
|
-
export { useComponent } from "./use-component/use-component
|
|
4
|
-
export { useCommandState } from "./use-command/use-command-state
|
|
5
|
-
export { useComponentWithRef } from "./use-component/use-component-with-ref
|
|
6
|
-
export { useCommandRunner } from "./use-command/use-command-runner
|
|
7
|
-
export { useCommandHook } from "./use-command/use-command-hook
|
|
8
|
-
export { useChildCommandHook } from "./use-child-command/use-child-command-hook
|
|
9
|
-
export { useChildCommandRunner } from "./use-child-command/use-child-command-runner
|
|
2
|
+
export { useCommand } from "./use-command/use-command";
|
|
3
|
+
export { useComponent } from "./use-component/use-component";
|
|
4
|
+
export { useCommandState } from "./use-command/use-command-state";
|
|
5
|
+
export { useComponentWithRef } from "./use-component/use-component-with-ref";
|
|
6
|
+
export { useCommandRunner } from "./use-command/use-command-runner";
|
|
7
|
+
export { useCommandHook } from "./use-command/use-command-hook";
|
|
8
|
+
export { useChildCommandHook } from "./use-child-command/use-child-command-hook";
|
|
9
|
+
export { useChildCommandRunner } from "./use-child-command/use-child-command-runner";
|
|
10
10
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
import { useCommanderChildrenComponents } from "../utils
|
|
4
|
+
import { useCommanderChildrenComponents } from "../utils";
|
|
5
5
|
|
|
6
|
-
import type { useComponent } from "../use-component/use-component
|
|
7
|
-
import type { DCommandArgs } from "../../definitions
|
|
6
|
+
import type { useComponent } from "../use-component/use-component";
|
|
7
|
+
import type { DCommandArgs } from "../../definitions";
|
|
8
8
|
|
|
9
9
|
export function useChildCommandHook(
|
|
10
10
|
childComponentName: string,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
import { useCommanderChildrenComponents } from "../utils
|
|
4
|
+
import { useCommanderChildrenComponents } from "../utils";
|
|
5
5
|
|
|
6
|
-
import type { DCommandArgs, DCommandSingleComponentContext } from "../../definitions
|
|
6
|
+
import type { DCommandArgs, DCommandSingleComponentContext } from "../../definitions";
|
|
7
7
|
|
|
8
8
|
export function useChildCommandRunner(
|
|
9
9
|
childComponentName: string,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
import { useCommand } from "./use-command
|
|
4
|
+
import { useCommand } from "./use-command";
|
|
5
5
|
|
|
6
|
-
import type { DCommandArgs } from "../../definitions
|
|
6
|
+
import type { DCommandArgs } from "../../definitions";
|
|
7
7
|
|
|
8
8
|
export function useCommandHook(
|
|
9
9
|
commandName: string,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
import { useCommand } from "./use-command
|
|
4
|
+
import { useCommand } from "./use-command";
|
|
5
5
|
|
|
6
|
-
import type { DCommandArgs } from "../../definitions
|
|
6
|
+
import type { DCommandArgs } from "../../definitions";
|
|
7
7
|
|
|
8
8
|
export function useCommandRunner( commandName: string, ref?: React.RefObject<any> ) {
|
|
9
9
|
const cmd = ref ? useCommand( commandName, ref ) : useCommand( commandName );
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
import { useCommand } from "./use-command
|
|
4
|
+
import { useCommand } from "./use-command";
|
|
5
5
|
|
|
6
|
-
import { getSafeContext, shallowEqual } from "../utils
|
|
6
|
+
import { getSafeContext, shallowEqual } from "../utils";
|
|
7
7
|
|
|
8
|
-
import core from "../../_internal/core
|
|
9
|
-
import { INTERNAL_STATE_UPDATED_EVENT, GET_INTERNAL_SYMBOL } from "../../_internal/constants
|
|
8
|
+
import core from "../../_internal/core";
|
|
9
|
+
import { INTERNAL_STATE_UPDATED_EVENT, GET_INTERNAL_SYMBOL } from "../../_internal/constants";
|
|
10
10
|
|
|
11
11
|
function resolveInternalContext( name: string ) {
|
|
12
12
|
const cmd = useCommand( name );
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
import { GET_INTERNAL_SYMBOL, GET_INTERNAL_MATCH_SYMBOL } from "../../_internal/constants
|
|
4
|
+
import { GET_INTERNAL_SYMBOL, GET_INTERNAL_MATCH_SYMBOL } from "../../_internal/constants";
|
|
5
5
|
|
|
6
|
-
import core from "../../_internal/core
|
|
7
|
-
import { ComponentIdContext } from "../../commands-context
|
|
8
|
-
import commandsManager from "../../commands-manager
|
|
6
|
+
import core from "../../_internal/core";
|
|
7
|
+
import { ComponentIdContext } from "../../commands-context";
|
|
8
|
+
import commandsManager from "../../commands-manager";
|
|
9
9
|
|
|
10
|
-
import type { DCommandArgs, DCommandIdArgs, DCommandSingleComponentContext } from "../../definitions
|
|
10
|
+
import type { DCommandArgs, DCommandIdArgs, DCommandSingleComponentContext } from "../../definitions";
|
|
11
11
|
|
|
12
12
|
type CommandRun = ( args?: DCommandArgs, callback?: ( result: unknown ) => void ) => unknown
|
|
13
13
|
type CommandHook = ( callback: ( result: unknown, args?: DCommandArgs ) => void ) => void
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
import { useComponent } from "./use-component
|
|
4
|
+
import { useComponent } from "./use-component";
|
|
5
5
|
|
|
6
|
-
import core from "../../_internal/core
|
|
6
|
+
import core from "../../_internal/core";
|
|
7
7
|
|
|
8
|
-
import { GET_INTERNAL_MATCH_SYMBOL } from "../../_internal/constants
|
|
8
|
+
import { GET_INTERNAL_MATCH_SYMBOL } from "../../_internal/constants";
|
|
9
9
|
|
|
10
10
|
export function useComponentWithRef( componentName: string, ref: React.RefObject<any> ): ReturnType<typeof useComponent> | null {
|
|
11
11
|
const [ id, setId ] = React.useState<ReturnType<typeof useComponent> | null>( null );
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
import { GET_INTERNAL_SYMBOL } from "../../_internal/constants
|
|
4
|
+
import { GET_INTERNAL_SYMBOL } from "../../_internal/constants";
|
|
5
5
|
|
|
6
|
-
import core from "../../_internal/core
|
|
7
|
-
import commandsManager from "../../commands-manager
|
|
8
|
-
import { ComponentIdContext } from "../../commands-context
|
|
6
|
+
import core from "../../_internal/core";
|
|
7
|
+
import commandsManager from "../../commands-manager";
|
|
8
|
+
import { ComponentIdContext } from "../../commands-context";
|
|
9
9
|
|
|
10
|
-
import type { DCommandArgs, DCommandComponentContextProps, DCommandHookHandle } from "../../definitions
|
|
10
|
+
import type { DCommandArgs, DCommandComponentContextProps, DCommandHookHandle } from "../../definitions";
|
|
11
11
|
|
|
12
12
|
export function getSafeContext( componentName: string, context?: DCommandComponentContextProps ) {
|
|
13
13
|
function maybeWrongContext( componentName: string, componentNameUnique: string ) {
|
package/src/hooks/utils.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
import { useComponent } from "./use-component/use-component
|
|
4
|
+
import { useComponent } from "./use-component/use-component";
|
|
5
5
|
|
|
6
|
-
import { ComponentIdContext } from "../commands-context
|
|
7
|
-
import commandsManager from "../commands-manager
|
|
6
|
+
import { ComponentIdContext } from "../commands-context";
|
|
7
|
+
import commandsManager from "../commands-manager";
|
|
8
8
|
|
|
9
|
-
import type { DCommandComponentContextProps } from "../definitions
|
|
9
|
+
import type { DCommandComponentContextProps } from "../definitions";
|
|
10
10
|
|
|
11
|
-
export { getSafeContext } from "./use-component/use-component
|
|
11
|
+
export { getSafeContext } from "./use-component/use-component";
|
|
12
12
|
|
|
13
13
|
export function shallowEqual<T extends Record<string, unknown>>( a: T, b: T ): boolean {
|
|
14
14
|
if ( a === b ) return true;
|
package/src/with-commands.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import EventEmitter from "eventemitter3";
|
|
2
2
|
|
|
3
3
|
import React from "react";
|
|
4
4
|
|
|
@@ -14,9 +14,9 @@ import {
|
|
|
14
14
|
INTERNAL_ON_LOAD,
|
|
15
15
|
INTERNAL_ON_CONTEXT_STATE_UPDATED,
|
|
16
16
|
INTERNAL_STATE_UPDATED_EVENT
|
|
17
|
-
} from "./_internal/constants
|
|
17
|
+
} from "./_internal/constants";
|
|
18
18
|
|
|
19
|
-
import core from "./_internal/core
|
|
19
|
+
import core from "./_internal/core";
|
|
20
20
|
|
|
21
21
|
import { ComponentIdContext } from "@zenflux/react-commander/commands-context";
|
|
22
22
|
|
|
@@ -193,7 +193,7 @@ export function withCommands(
|
|
|
193
193
|
getComponentContext: () => self.context,
|
|
194
194
|
|
|
195
195
|
getState: () => this.store ? this.store.getState() : this.state,
|
|
196
|
-
setState: ( state
|
|
196
|
+
setState: ( state, callback ) => {
|
|
197
197
|
const prevState = this.store.getState();
|
|
198
198
|
|
|
199
199
|
this.store.setState(
|
|
@@ -324,7 +324,7 @@ export function withCommands(
|
|
|
324
324
|
* React `useId` behave differently in production and development mode, because of `<React.StrictMode>`
|
|
325
325
|
* https://github.com/facebook/react/issues/27103#issuecomment-1763359077
|
|
326
326
|
*/
|
|
327
|
-
const UniqueWrappedComponent = React.forwardRef( ( props: any, _ref
|
|
327
|
+
const UniqueWrappedComponent = React.forwardRef( ( props: any, _ref ) => {
|
|
328
328
|
const parentContext = React.useContext( ComponentIdContext );
|
|
329
329
|
|
|
330
330
|
const componentNameUnique = `${ componentName }-${ React.useId() }`;
|