Skip to content

Commit

Permalink
version: 1.0.2
Browse files Browse the repository at this point in the history
add eslint
add prettier
add github actions
move source files to src
add license
add npmignore
  • Loading branch information
vhgn committed Nov 29, 2022
1 parent 14864cc commit 1a24973
Show file tree
Hide file tree
Showing 11 changed files with 1,613 additions and 99 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
37 changes: 37 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"root": true,
"extends": [
"prettier",
"plugin:prettier/recommended",
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"prettier",
"react",
"react-hooks"
],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off"
},
"settings": {
"react": {
"version": "detect"
}
},
"env": {
"browser": true,
"node": true
},
"globals": {
"JSX": true
}
}
30 changes: 30 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: build
on:
release:
types: [ published ]
jobs:
build:
runs-on: ubuntu-latest

steps:

- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
registry-url: https://registry.npmjs.org/

- name: Install dependencies
run: yarn && yarn install

- name: Build
run: yarn build

- name: Publish
run: yarn publish

env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Empty file added .prettierrc
Empty file.
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Copyright 2022 Vahagn

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

76 changes: 0 additions & 76 deletions index.tsx

This file was deleted.

59 changes: 44 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
{
"name": "video-provider",
"version": "1.0.1",
"description": "React state manager for videos",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"repository": "https://github.com/vhgn/video-provider",
"author": "Vahagn",
"license": "MIT",
"devDependencies": {
"@types/react": "^18.0.25",
"typescript": "^4.9.3"
},
"dependencies": {
"react": "^18.2.0"
}
"name": "video-provider",
"version": "1.0.2",
"description": "React state manager for videos",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"repository": "https://github.com/vhgn/video-provider",
"author": "Vahagn",
"license": "MIT",
"devDependencies": {
"@types/react": "^18.0.25",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "^2.8.0",
"typescript": "^4.9.3"
},
"dependencies": {
"react": "^18.2.0"
},
"peerDependencies": {
"react": ">=16"
},
"scripts": {
"build": "yarn build:esm && yarn build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir dist/cjs",
"lint": "eslint \"{**/*,*}.{js,ts,jsx,tsx}\"",
"prettier": "prettier --write \"./**/*.{js,ts,jsx,tsx}\""
},
"files": [
"dist",
"LICENSE",
"README.md"
],
"keywords": [
"react",
"video",
"provider"
]
}
83 changes: 83 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, {
createContext,
ReactNode,
RefObject,
useCallback,
useEffect,
useState,
} from "react";

export type VideoContextValue = {
now: number;
duration: number;
paused: boolean;
muted: boolean;
volume: number;

play: () => void;
pause: () => void;
mute: (status: boolean) => void;
setVolume: (value: number) => void;
};

export const VideoContext = createContext<VideoContextValue | null>(null);

export interface VideoProviderProps {
element: RefObject<HTMLVideoElement>;
children: ReactNode;
}

export const VideoProvider = (props: VideoProviderProps) => {
const { element, children } = props;

const [paused, setPaused] = useState(true);
const [muted, mute] = useState(false);
const [volume, setVolume] = useState(1);
const [now, setNow] = useState(0);
const [duration, setDuration] = useState(0);

useEffect(() => {
if (element.current === null) return;

element.current.muted = muted;
element.current.volume = volume;
}, [element, muted, volume]);

useEffect(() => {
const current = element.current;
if (current === null) return;

current.onplay = () => setPaused(false);
current.onpause = () => setPaused(true);
current.onvolumechange = () => setVolume(current.volume);
current.ontimeupdate = () => setNow(current.currentTime);
current.ondurationchange = () => setDuration(current.duration);
}, [element, paused]);

useEffect(() => {
if (element.current === null) return;

element.current.muted = muted;
}, [element, muted]);

const play = useCallback(() => element.current?.play(), [element]);
const pause = useCallback(() => element.current?.pause(), [element]);

return (
<VideoContext.Provider
value={{
now,
duration,
muted,
paused,
volume,
play,
pause,
mute,
setVolume,
}}
>
{children}
</VideoContext.Provider>
);
};
25 changes: 18 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
{
"include": ["src"],
"exclude": [
"dist",
"node_modules"
],
"compilerOptions": {
"target": "es2016",
"jsx": "preserve",
"module": "commonjs",
"module": "esnext",
"lib": ["dom", "esnext"],
"importHelpers": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"outDir": "./dist/esm",
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"moduleResolution": "node",
"jsx": "react",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
Loading

0 comments on commit 1a24973

Please sign in to comment.