diff --git a/.babelrc b/.babelrc index c9b2865..2417bbb 100644 --- a/.babelrc +++ b/.babelrc @@ -1,17 +1,3 @@ { - "plugins": [ - "@babel/plugin-proposal-class-properties" - ], - "presets": [ - "@babel/preset-react", - [ - "@babel/preset-env", - { - "targets": { - "edge": "14" - }, - "modules": "commonjs" - } - ] - ] -} \ No newline at end of file + "extends": "sanipack/babel" +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e55113f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +; editorconfig.org +root = true +charset= utf8 + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index 72f72df..df1e6da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,54 @@ -.DS_Store +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories node_modules -lib \ No newline at end of file +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +# macOS finder cache file +.DS_Store + +# VS Code settings +.vscode + +# Lockfiles +yarn.lock +package-lock.json + +# Cache +.cache + +# Compiled plugin +/lib + diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..3b109af --- /dev/null +++ b/.npmignore @@ -0,0 +1,9 @@ +/test +/coverage +.editorconfig +.eslintrc +.gitignore +.github +.prettierrc +.travis.yml +.nyc_output diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index de2f53c..0000000 --- a/.prettierrc.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - singleQuote: true, - trailingComma: 'all', -}; diff --git a/package-lock.json b/package-lock.json index d006786..5792a89 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,13 @@ { "name": "sanity-plugin-table", - "version": "2.1.0", + "version": "2.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "sanity-plugin-table", - "version": "1.0.0", + "version": "2.1.0", "license": "MIT", "devDependencies": { - "@types/prop-types": "^15.7.3", "@types/react": "^17.0.3", "eslint": "7.22.0", "eslint-config-prettier": "8.1.0", @@ -19,8 +17,8 @@ "sanipack": "1.0.8" }, "peerDependencies": { + "@sanity/icons": "^1.0.1", "@sanity/ui": "^0.33.10", - "prop-types": "15.7.2", "react": "^17.0.1", "react-dom": "^17.0.1", "styled-components": "^5.2.1" diff --git a/package.json b/package.json index 2dc6451..74ef766 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sanity-plugin-table", - "version": "2.1.0", + "version": "2.1.1", "description": "Table schema type and input component for Sanity CMS", "main": "lib/TableComponent.js", "scripts": { @@ -19,6 +19,7 @@ ], "license": "MIT", "peerDependencies": { + "@sanity/uuid": "^3.0.1", "@sanity/icons": "^1.0.1", "@sanity/ui": "^0.33.10", "react": "^17.0.1", diff --git a/src/TableComponent.tsx b/src/TableComponent.tsx index d71f43c..99ab1e4 100644 --- a/src/TableComponent.tsx +++ b/src/TableComponent.tsx @@ -1,5 +1,5 @@ import React, { useState, FunctionComponent, forwardRef } from 'react'; -import { randomKey } from '@sanity/util/lib/pathUtils'; +import { uuid } from '@sanity/uuid'; import FormField from 'part:@sanity/components/formfields/default'; import PatchEvent, { set, unset } from 'part:@sanity/form-builder/patch-event'; import config from 'config:table'; @@ -8,20 +8,6 @@ import TableInput from './components/TableInput'; import TableMenu from './components/TableMenu'; import { Box, Button, Card, Dialog, Flex, Inline, Text } from '@sanity/ui'; -interface RootProps { - level: number; - markers: any[]; - type: { - title: string; - description: string; - options: Record; - }; - value: { - rows: TableRow[]; - }; - onChange: (...any) => any; -} - // This probably isn't necessary anymore function deepClone(obj: T): T { return JSON.parse(JSON.stringify(obj)); @@ -47,12 +33,12 @@ const TableComponent: FunctionComponent = (props) => { rows: [ { _type: config.rowType, - _key: randomKey(), + _key: uuid(), cells: ['', ''], }, { _type: config.rowType, - _key: randomKey(), + _key: uuid(), cells: ['', ''], }, ], @@ -77,7 +63,7 @@ const TableComponent: FunctionComponent = (props) => { // Add as many cells as we have columns newValue.rows.push({ _type: config.rowType, - _key: randomKey(), + _key: uuid(), cells: Array(columnCount).fill(''), }); } diff --git a/src/types.ts b/src/types.ts index ca7127d..3bc3ddb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,17 @@ +interface RootProps { + level: number; + markers: any[]; + type: { + title: string; + description: string; + options: Record; + }; + value: { + rows: TableRow[]; + }; + onChange: (...any) => any; +} + interface TableRow { _type: string; _key: string; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..40b6713 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + // Note: This config is only used to help editors like VS Code understand/resolve + // parts, the actual transpilation is done by babel. Any compiler configuration in + // here will be ignored. + "compilerOptions": { + "esModuleInterop": true, + "jsx": "react", + "lib": ["ES2019"] + }, + "include": [ + "./node_modules/@sanity/base/types/**/*.ts", + "./**/*.ts", + "./**/*.tsx" + ] +}