@cord-sdk/react
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,2 +0,2 @@ | ||
import { PropsWithStandardHTMLAttributes, CollaborationReactComponentProps } from '@cord-sdk/types'; | ||
import type { PropsWithStandardHTMLAttributes, CollaborationReactComponentProps } from '@cord-sdk/types'; | ||
export declare function Collaboration(props: PropsWithStandardHTMLAttributes<CollaborationReactComponentProps>): JSX.Element; |
@@ -1,2 +0,2 @@ | ||
import { PropsWithStandardHTMLAttributes, MultipleCursorsReactComponentProps } from '@cord-sdk/types'; | ||
import type { PropsWithStandardHTMLAttributes, MultipleCursorsReactComponentProps } from '@cord-sdk/types'; | ||
export declare function MultipleCursors(props: PropsWithStandardHTMLAttributes<MultipleCursorsReactComponentProps>): JSX.Element; |
@@ -1,2 +0,2 @@ | ||
import { PagePresenceReactComponentProps, PropsWithStandardHTMLAttributes } from '@cord-sdk/types'; | ||
import type { PagePresenceReactComponentProps, PropsWithStandardHTMLAttributes } from '@cord-sdk/types'; | ||
export declare function PagePresence(props: PropsWithStandardHTMLAttributes<PagePresenceReactComponentProps>): JSX.Element; |
@@ -1,2 +0,2 @@ | ||
import { PresenceFacepileReactComponentProps, PropsWithStandardHTMLAttributes } from '@cord-sdk/types'; | ||
import type { PresenceFacepileReactComponentProps, PropsWithStandardHTMLAttributes } from '@cord-sdk/types'; | ||
export declare function PresenceFacepile(props: PropsWithStandardHTMLAttributes<PresenceFacepileReactComponentProps>): JSX.Element; |
@@ -1,2 +0,2 @@ | ||
import { PresenceObserverReactComponentProps, PropsWithStandardHTMLAttributes } from '@cord-sdk/types'; | ||
import type { PresenceObserverReactComponentProps, PropsWithStandardHTMLAttributes } from '@cord-sdk/types'; | ||
export declare function PresenceObserver(props: PropsWithStandardHTMLAttributes<PresenceObserverReactComponentProps>): JSX.Element; |
@@ -1,2 +0,2 @@ | ||
import { PropsWithStandardHTMLAttributes, SidebarReactComponentProps } from '@cord-sdk/types'; | ||
import type { PropsWithStandardHTMLAttributes, SidebarReactComponentProps } from '@cord-sdk/types'; | ||
export declare function Sidebar(props: PropsWithStandardHTMLAttributes<SidebarReactComponentProps>): JSX.Element; |
@@ -1,2 +0,2 @@ | ||
import { PropsWithStandardHTMLAttributes, SidebarLauncherReactComponentProps } from '@cord-sdk/types'; | ||
import type { PropsWithStandardHTMLAttributes, SidebarLauncherReactComponentProps } from '@cord-sdk/types'; | ||
export declare function SidebarLauncher(props: PropsWithStandardHTMLAttributes<SidebarLauncherReactComponentProps>): JSX.Element; |
@@ -1,2 +0,2 @@ | ||
import { TextReactComponentProps, PropsWithStandardHTMLAttributes } from '@cord-sdk/types'; | ||
import type { TextReactComponentProps, PropsWithStandardHTMLAttributes } from '@cord-sdk/types'; | ||
export declare function Text(props: PropsWithStandardHTMLAttributes<TextReactComponentProps>): JSX.Element; |
@@ -1,2 +0,3 @@ | ||
import { PropsWithStandardHTMLAttributes, ThreadReactComponentProps } from '@cord-sdk/types'; | ||
export declare function Thread(props: PropsWithStandardHTMLAttributes<ThreadReactComponentProps>): JSX.Element; | ||
import type { PropsWithChildren } from 'react'; | ||
import type { PropsWithStandardHTMLAttributes, ThreadReactComponentProps } from '@cord-sdk/types'; | ||
export declare function Thread(props: PropsWithChildren<PropsWithStandardHTMLAttributes<ThreadReactComponentProps>>): JSX.Element; |
import React from 'react'; | ||
import { ICordSDK, Context } from '@cord-sdk/types'; | ||
import type { ICordSDK, Context, NavigateFn } from '@cord-sdk/types'; | ||
declare type CordContextValue = { | ||
@@ -12,5 +12,7 @@ sdk: ICordSDK | null; | ||
enableTasks?: boolean; | ||
enableAnnotations?: boolean; | ||
cordScriptUrl?: string; | ||
navigate?: NavigateFn | null; | ||
}; | ||
export declare function CordProvider({ clientAuthToken, enableTasks, cordScriptUrl, children, }: React.PropsWithChildren<Props>): JSX.Element; | ||
export declare function CordProvider({ clientAuthToken, enableTasks, enableAnnotations, cordScriptUrl, navigate, children, }: React.PropsWithChildren<Props>): JSX.Element; | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
import { Context } from '@cord-sdk/types'; | ||
import type { Context } from '@cord-sdk/types'; | ||
export declare function useCordContext(newContext?: Context): Context | undefined; |
@@ -0,3 +1,4 @@ | ||
/// <reference types="react" /> | ||
export declare function useCustomEventListeners<T extends Record<string, unknown[]>>(events: { | ||
[P in keyof T]: ((...args: T[P]) => unknown) | undefined; | ||
}): import("react").Dispatch<import("react").SetStateAction<Element | null>>; |
@@ -14,37 +14,10 @@ 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function useCustomEventListeners(events) { | ||
var _a = React.useState(null), element = _a[0], setElement = _a[1]; | ||
React.useEffect(function () { | ||
const [element, setElement] = React.useState(null); | ||
React.useEffect(() => { | ||
if (!element) { | ||
return; | ||
} | ||
var handlers = Object.entries(events).map(function (_a) { | ||
var event = _a[0], callback = _a[1]; | ||
var customEventHandler = function (e) { | ||
const handlers = Object.entries(events).map(([event, callback]) => { | ||
const customEventHandler = (e) => { | ||
if (e instanceof CustomEvent) { | ||
@@ -54,9 +27,8 @@ callback === null || callback === void 0 ? void 0 : callback.apply(null, e.detail); | ||
}; | ||
var eventName = "".concat(element.nodeName.toLowerCase(), ":").concat(event); | ||
const eventName = `${element.nodeName.toLowerCase()}:${event}`; | ||
element.addEventListener(eventName, customEventHandler); | ||
return [eventName, customEventHandler]; | ||
}); | ||
return function () { | ||
for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) { | ||
var _a = handlers_1[_i], eventName = _a[0], handler = _a[1]; | ||
return () => { | ||
for (const [eventName, handler] of handlers) { | ||
element.removeEventListener(eventName, handler); | ||
@@ -69,18 +41,11 @@ } | ||
var propsToAttributes$8 = components.propsToAttributeConverter(components.componentAttributes.Collaboration); | ||
function Collaboration(props) { | ||
var setRef = useCustomEventListeners({}); | ||
return (React__default["default"].createElement("cord-collaboration", __assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$8(props)))); | ||
} | ||
var CordContext = React__default["default"].createContext({ | ||
const CordContext = React__default["default"].createContext({ | ||
sdk: null, | ||
context: undefined, | ||
setContext: function () { return undefined; }, | ||
setContext: () => undefined, | ||
}); | ||
function CordProvider(_a) { | ||
var clientAuthToken = _a.clientAuthToken, enableTasks = _a.enableTasks, cordScriptUrl = _a.cordScriptUrl, children = _a.children; | ||
var _b = React.useState(null), sdk = _b[0], setSDK = _b[1]; | ||
var _c = React.useState(), context = _c[0], setContext = _c[1]; | ||
React.useEffect(function () { | ||
function CordProvider({ clientAuthToken, enableTasks, enableAnnotations, cordScriptUrl, navigate, children, }) { | ||
const [sdk, setSDK] = React.useState(null); | ||
const [context, setContext] = React.useState(); | ||
React.useEffect(() => { | ||
if (window.CordSDK) { | ||
@@ -90,3 +55,3 @@ setSDK(window.CordSDK); | ||
} | ||
var onLoad = function () { | ||
const onLoad = () => { | ||
if (!window.CordSDK) { | ||
@@ -98,8 +63,8 @@ console.warn('CordSDK failed to load'); | ||
}; | ||
var scriptTag = document.createElement('script'); | ||
const scriptTag = document.createElement('script'); | ||
scriptTag.src = | ||
cordScriptUrl !== null && cordScriptUrl !== void 0 ? cordScriptUrl : "https://app.cord.com/sdk/v1/sdk.latest.js"; | ||
cordScriptUrl !== null && cordScriptUrl !== void 0 ? cordScriptUrl : `https://app.cord.com/sdk/v1/sdk.latest.js`; | ||
scriptTag.addEventListener('load', onLoad); | ||
document.head.appendChild(scriptTag); | ||
return function () { | ||
return () => { | ||
scriptTag.removeEventListener('load', onLoad); | ||
@@ -109,3 +74,3 @@ scriptTag.remove(); | ||
}, [cordScriptUrl]); | ||
React.useEffect(function () { | ||
React.useEffect(() => { | ||
if (sdk && clientAuthToken) { | ||
@@ -116,7 +81,9 @@ sdk | ||
enable_tasks: enableTasks, | ||
enable_annotations: enableAnnotations, | ||
navigate, | ||
}) | ||
.then(function () { | ||
.then(() => { | ||
setSDK(sdk); | ||
}); | ||
return function () { | ||
return () => { | ||
sdk.destroy(); | ||
@@ -128,16 +95,10 @@ }; | ||
} | ||
}, [sdk, clientAuthToken, enableTasks]); | ||
var value = React.useMemo(function () { return ({ sdk: sdk, context: context, setContext: setContext }); }, [sdk, context, setContext]); | ||
}, [sdk, clientAuthToken, enableTasks, enableAnnotations, navigate]); | ||
const value = React.useMemo(() => ({ sdk, context, setContext }), [sdk, context, setContext]); | ||
return React__default["default"].createElement(CordContext.Provider, { value: value }, children); | ||
} | ||
var propsToAttributes$7 = components.propsToAttributeConverter(components.componentAttributes.MultipleCursors); | ||
function MultipleCursors(props) { | ||
var setRef = useCustomEventListeners({}); | ||
return (React__default["default"].createElement("cord-multiple-cursors", __assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$7(props)))); | ||
} | ||
function useCordContext(newContext) { | ||
var _a = React.useContext(CordContext), context = _a.context, setContext = _a.setContext; | ||
React.useEffect(function () { | ||
const { context, setContext } = React.useContext(CordContext); | ||
React.useEffect(() => { | ||
if (newContext && !isEqual__default["default"](context, newContext)) { | ||
@@ -147,4 +108,4 @@ setContext(newContext); | ||
}, [newContext, context, setContext]); | ||
React.useEffect(function () { | ||
return function () { | ||
React.useEffect(() => { | ||
return () => { | ||
setContext(undefined); | ||
@@ -156,66 +117,82 @@ }; | ||
var propsToAttributes$6 = components.propsToAttributeConverter(components.componentAttributes.PagePresence); | ||
const propsToAttributes$8 = components.propsToAttributeConverter(components.componentAttributes.Collaboration); | ||
function Collaboration(props) { | ||
const setRef = useCustomEventListeners({}); | ||
const context = useCordContext(); | ||
return (React__default["default"].createElement("cord-collaboration", Object.assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$8(Object.assign({ context }, props))))); | ||
} | ||
const propsToAttributes$7 = components.propsToAttributeConverter(components.componentAttributes.MultipleCursors); | ||
function MultipleCursors(props) { | ||
const setRef = useCustomEventListeners({}); | ||
const context = useCordContext(); | ||
return (React__default["default"].createElement("cord-multiple-cursors", Object.assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$7(Object.assign({ context }, props))))); | ||
} | ||
const propsToAttributes$6 = components.propsToAttributeConverter(components.componentAttributes.PagePresence); | ||
function PagePresence(props) { | ||
var onUpdate = props.onUpdate; | ||
var setRef = useCustomEventListeners({ | ||
const { onUpdate } = props; | ||
const setRef = useCustomEventListeners({ | ||
update: onUpdate, | ||
}); | ||
var context = useCordContext(); | ||
return (React__default["default"].createElement("cord-page-presence", __assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$6(__assign({ context: context }, props))))); | ||
const context = useCordContext(); | ||
return (React__default["default"].createElement("cord-page-presence", Object.assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$6(Object.assign({ context }, props))))); | ||
} | ||
var propsToAttributes$5 = components.propsToAttributeConverter(components.componentAttributes.PresenceFacepile); | ||
const propsToAttributes$5 = components.propsToAttributeConverter(components.componentAttributes.PresenceFacepile); | ||
function PresenceFacepile(props) { | ||
var onUpdate = props.onUpdate; | ||
var setRef = useCustomEventListeners({ | ||
const { onUpdate } = props; | ||
const setRef = useCustomEventListeners({ | ||
update: onUpdate, | ||
}); | ||
var context = useCordContext(); | ||
return (React__default["default"].createElement("cord-presence-facepile", __assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$5(__assign({ context: context }, props))))); | ||
const context = useCordContext(); | ||
return (React__default["default"].createElement("cord-presence-facepile", Object.assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$5(Object.assign({ context }, props))))); | ||
} | ||
var propsToAttributes$4 = components.propsToAttributeConverter(components.componentAttributes.PresenceObserver); | ||
const propsToAttributes$4 = components.propsToAttributeConverter(components.componentAttributes.PresenceObserver); | ||
function PresenceObserver(props) { | ||
var onChange = props.onChange; | ||
var setRef = useCustomEventListeners({ | ||
const { onChange } = props; | ||
const setRef = useCustomEventListeners({ | ||
change: onChange, | ||
}); | ||
var context = useCordContext(); | ||
return (React__default["default"].createElement("cord-presence-observer", __assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$4(__assign({ context: context }, props))), props.children)); | ||
const context = useCordContext(); | ||
return (React__default["default"].createElement("cord-presence-observer", Object.assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$4(Object.assign({ context }, props))), props.children)); | ||
} | ||
var propsToAttributes$3 = components.propsToAttributeConverter(components.componentAttributes.Sidebar); | ||
const propsToAttributes$3 = components.propsToAttributeConverter(components.componentAttributes.Sidebar); | ||
function Sidebar(props) { | ||
var onOpen = props.onOpen, onClose = props.onClose; | ||
var setRef = useCustomEventListeners({ | ||
const { onOpen, onClose } = props; | ||
const setRef = useCustomEventListeners({ | ||
open: onOpen, | ||
close: onClose, | ||
}); | ||
return (React__default["default"].createElement("cord-sidebar", __assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$3(props)))); | ||
const context = useCordContext(); | ||
return (React__default["default"].createElement("cord-sidebar", Object.assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$3(Object.assign({ context }, props))))); | ||
} | ||
var propsToAttributes$2 = components.propsToAttributeConverter(components.componentAttributes.SidebarLauncher); | ||
const propsToAttributes$2 = components.propsToAttributeConverter(components.componentAttributes.SidebarLauncher); | ||
function SidebarLauncher(props) { | ||
var onClick = props.onClick; | ||
var setRef = useCustomEventListeners({ | ||
const { onClick } = props; | ||
const setRef = useCustomEventListeners({ | ||
click: onClick, | ||
}); | ||
return (React__default["default"].createElement("cord-sidebar-launcher", __assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$2(props)))); | ||
return (React__default["default"].createElement("cord-sidebar-launcher", Object.assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$2(props)))); | ||
} | ||
var propsToAttributes$1 = components.propsToAttributeConverter(components.componentAttributes.Text); | ||
const propsToAttributes$1 = components.propsToAttributeConverter(components.componentAttributes.Text); | ||
function Text(props) { | ||
var onBoop = props.onBoop; | ||
var setRef = useCustomEventListeners({ | ||
const { onBoop } = props; | ||
const setRef = useCustomEventListeners({ | ||
boop: onBoop, | ||
}); | ||
return (React__default["default"].createElement("cord-text", __assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$1(props)))); | ||
return (React__default["default"].createElement("cord-text", Object.assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes$1(props)))); | ||
} | ||
var propsToAttributes = components.propsToAttributeConverter(components.componentAttributes.Thread); | ||
const propsToAttributes = components.propsToAttributeConverter(components.componentAttributes.Thread); | ||
function Thread(props) { | ||
var setRef = useCustomEventListeners({ | ||
const setRef = useCustomEventListeners({ | ||
threadcreated: props.onThreadCreated, | ||
}); | ||
return (React__default["default"].createElement("cord-thread", __assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes(props)))); | ||
const context = useCordContext(); | ||
return (React__default["default"].createElement("cord-thread", Object.assign({ id: props.id, class: props.className, ref: setRef }, propsToAttributes(Object.assign({ context }, props))), props.children)); | ||
} | ||
@@ -222,0 +199,0 @@ |
{ | ||
"name": "@cord-sdk/react", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"homepage": "https://docs.cord.com/", | ||
@@ -22,3 +22,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@cord-sdk/components": "*", | ||
"@cord-sdk/components": "0.0.4", | ||
"lodash": "^4.17.21" | ||
@@ -30,3 +30,3 @@ }, | ||
"devDependencies": { | ||
"@cord-sdk/jsx": "*", | ||
"@cord-sdk/jsx": "0.0.4", | ||
"@types/lodash-es": "^4.17.6", | ||
@@ -33,0 +33,0 @@ "@types/react": "^17.0.43", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
1
21498
406
+ Added@cord-sdk/components@0.0.4(transitive)
+ Added@cord-sdk/types@0.0.4(transitive)
- Removed@cord-sdk/components@1.47.2(transitive)
- Removed@cord-sdk/types@1.47.2(transitive)
Updated@cord-sdk/components@0.0.4