From 18a18b14cf3c47cb283c2fd36802b3f5d9b6deca Mon Sep 17 00:00:00 2001 From: rdunk Date: Fri, 12 Jan 2024 14:43:45 +0000 Subject: [PATCH 1/5] feature: add configurable row type --- src/index.ts | 88 +++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5ceb0c7..9f98232 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,52 +9,56 @@ export type { export { TableComponent, TablePreview }; -const tableRowSchema = defineType({ - title: 'Table Row', - name: 'tableRow', - type: 'object', - fields: [ - { - name: 'cells', - type: 'array', - of: [{ type: 'string' }], - }, - ], -}); +export interface TableConfig { + rowType?: string; +} + +export const table = definePlugin(config => { + const tableRowSchema = defineType({ + title: 'Table Row', + name: config?.rowType || 'tableRow', + type: 'object', + fields: [ + { + name: 'cells', + type: 'array', + of: [{ type: 'string' }], + }, + ], + }); -const tableSchema = defineType({ - title: 'Table', - name: 'table', - type: 'object', - fields: [ - { - name: 'rows', - type: 'array', - of: [ - { - type: tableRowSchema.name, - }, - ], + const tableSchema = defineType({ + title: 'Table', + name: 'table', + type: 'object', + fields: [ + { + name: 'rows', + type: 'array', + of: [ + { + type: tableRowSchema.name, + }, + ], + }, + ], + components: { + //TODO remove as any when rc.3 is released + input: TableComponent as any, + preview: TablePreview as any, }, - ], - components: { - //TODO remove as any when rc.3 is released - input: TableComponent as any, - preview: TablePreview as any, - }, - preview: { - select: { - rows: 'rows', - title: 'title', + preview: { + select: { + rows: 'rows', + title: 'title', + }, + prepare: ({ title, rows = [] }) => ({ + title, + rows, + }), }, - prepare: ({ title, rows = [] }) => ({ - title, - rows, - }), - }, -}); + }); -export const table = definePlugin(() => { return { name: 'table', schema: { From 672db1adb09e146fe41f587d47b1d9456c1be144 Mon Sep 17 00:00:00 2001 From: rdunk Date: Fri, 12 Jan 2024 14:55:09 +0000 Subject: [PATCH 2/5] style: remove todo comment --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 9f98232..09fe088 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,7 +43,6 @@ export const table = definePlugin(config => { }, ], components: { - //TODO remove as any when rc.3 is released input: TableComponent as any, preview: TablePreview as any, }, From 506cf3f141df7828c5c25454eae0afb683d23275 Mon Sep 17 00:00:00 2001 From: rdunk Date: Fri, 12 Jan 2024 15:21:12 +0000 Subject: [PATCH 3/5] docs: configuration --- README.md | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 690029d..0c6b1f1 100644 --- a/README.md +++ b/README.md @@ -11,18 +11,20 @@ Only the v3 version is maintained by Sanity.io. ## Acknowledgements Big thanks to the original contributors for their work! -* Original version: [rdunk/sanity-plugin-table](https://github.com/rdunk/sanity-plugin-table). -* Further improvements in fork [MathisBullinger/sanity-plugin-another-table](https://github.com/MathisBullinger/sanity-plugin-another-table). -* Initial V3 port: [bitfo/sanity-plugin-table](https://github.com/bitfo/sanity-plugin-table) + +- Original version: [rdunk/sanity-plugin-table](https://github.com/rdunk/sanity-plugin-table). +- Further improvements in fork [MathisBullinger/sanity-plugin-another-table](https://github.com/MathisBullinger/sanity-plugin-another-table). +- Initial V3 port: [bitfo/sanity-plugin-table](https://github.com/bitfo/sanity-plugin-table) ## Disclaimer Sometimes a table is just what you need. However, before using the Table plugin, consider if there are other ways to model your data that are: -* easier to edit and validate -* easier to query -Approaching your schemas in a more structured manner can often pay dividends down the line. +- easier to edit and validate +- easier to query + +Approaching your schemas in a more structured manner can often pay dividends down the line. ## Install @@ -73,6 +75,22 @@ export default defineConfig({ }); ``` +## Configuration + +You can optionally configure the `_type` used for the row object in the table schema by passing a configuration object when adding the plugin. For most users this is unnecessary, but it can be useful if you are migrating from a legacy table plugin. + +```js +export default defineConfig({ + // ... + plugins: [ + table({ + rowType: 'my-custom-row-type', + }), + ], + // ... +}); +``` + ## License [MIT](LICENSE) © ʞunp ʇɹǝdnɹ, Mathis Bullinger, Dave Lucia and Sanity.io From 5e9beaa297ab5a426178eba36a398b07cd1179f5 Mon Sep 17 00:00:00 2001 From: rdunk Date: Fri, 12 Jan 2024 15:26:54 +0000 Subject: [PATCH 4/5] docs: minor clarification --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c6b1f1..902e058 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ export default defineConfig({ ## Configuration -You can optionally configure the `_type` used for the row object in the table schema by passing a configuration object when adding the plugin. For most users this is unnecessary, but it can be useful if you are migrating from a legacy table plugin. +You can optionally configure the `_type` used for the row object in the table schema by passing a `rowType` when adding the plugin. For most users this is unnecessary, but it can be useful if you are migrating from a legacy table plugin. ```js export default defineConfig({ From d9fb680eb373319cc0e283443e3174ab356a3648 Mon Sep 17 00:00:00 2001 From: rdunk Date: Fri, 12 Jan 2024 15:28:46 +0000 Subject: [PATCH 5/5] docs: fix broken link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 902e058..c7cf86e 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ on how to run this plugin with hotreload in the studio. ### Release new version -Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-table/actions/workflows/main.yml). +Run ["CI & Release" workflow](https://github.com/sanity-io/table/actions/workflows/main.yml). Make sure to select the main branch and check "Release new version". Semantic release will only release on configured branches, so it is safe to run release on any branch.