@teipublisher/pb-components 1.26.0 → 1.27.0
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/CHANGELOG.md +15 -0
- package/css/gridjs/mermaid.min.css +1 -0
- package/dist/demo/demos.json +4 -1
- package/dist/demo/pb-table-grid.html +17 -0
- package/dist/demo/people.json +35 -0
- package/dist/pb-components-bundle.js +230 -211
- package/dist/pb-elements.json +184 -0
- package/package.json +2 -1
- package/pb-elements.json +184 -0
- package/src/pb-components.js +1 -0
- package/src/pb-table-column.js +66 -0
- package/src/pb-table-grid.js +190 -0
package/dist/pb-elements.json
CHANGED
|
@@ -8923,6 +8923,190 @@
|
|
|
8923
8923
|
}
|
|
8924
8924
|
]
|
|
8925
8925
|
},
|
|
8926
|
+
{
|
|
8927
|
+
"name": "pb-table-column",
|
|
8928
|
+
"path": "./src/pb-table-column.js",
|
|
8929
|
+
"description": "Defines a column within `pb-table-grid`.",
|
|
8930
|
+
"attributes": [
|
|
8931
|
+
{
|
|
8932
|
+
"name": "label",
|
|
8933
|
+
"description": "Column heading to display",
|
|
8934
|
+
"type": "string",
|
|
8935
|
+
"default": "\"no-label\""
|
|
8936
|
+
},
|
|
8937
|
+
{
|
|
8938
|
+
"name": "property",
|
|
8939
|
+
"description": "Name of the JSON property containing the data",
|
|
8940
|
+
"type": "string"
|
|
8941
|
+
},
|
|
8942
|
+
{
|
|
8943
|
+
"name": "sort",
|
|
8944
|
+
"description": "Should the column support sorting?",
|
|
8945
|
+
"type": "boolean",
|
|
8946
|
+
"default": "false"
|
|
8947
|
+
},
|
|
8948
|
+
{
|
|
8949
|
+
"name": "width",
|
|
8950
|
+
"description": "Optional fixed width of the column (e.g. '200px' or '30%')",
|
|
8951
|
+
"type": "string"
|
|
8952
|
+
}
|
|
8953
|
+
],
|
|
8954
|
+
"properties": [
|
|
8955
|
+
{
|
|
8956
|
+
"name": "label",
|
|
8957
|
+
"attribute": "label",
|
|
8958
|
+
"description": "Column heading to display",
|
|
8959
|
+
"type": "string",
|
|
8960
|
+
"default": "\"no-label\""
|
|
8961
|
+
},
|
|
8962
|
+
{
|
|
8963
|
+
"name": "property",
|
|
8964
|
+
"attribute": "property",
|
|
8965
|
+
"description": "Name of the JSON property containing the data",
|
|
8966
|
+
"type": "string"
|
|
8967
|
+
},
|
|
8968
|
+
{
|
|
8969
|
+
"name": "sort",
|
|
8970
|
+
"attribute": "sort",
|
|
8971
|
+
"description": "Should the column support sorting?",
|
|
8972
|
+
"type": "boolean",
|
|
8973
|
+
"default": "false"
|
|
8974
|
+
},
|
|
8975
|
+
{
|
|
8976
|
+
"name": "width",
|
|
8977
|
+
"attribute": "width",
|
|
8978
|
+
"description": "Optional fixed width of the column (e.g. '200px' or '30%')",
|
|
8979
|
+
"type": "string"
|
|
8980
|
+
}
|
|
8981
|
+
]
|
|
8982
|
+
},
|
|
8983
|
+
{
|
|
8984
|
+
"name": "pb-table-grid",
|
|
8985
|
+
"path": "./src/pb-table-grid.js",
|
|
8986
|
+
"description": "A table grid based on [gridjs](https://gridjs.io/), which loads its data from a server endpoint\nspecified in `source`. If `source` is a relative URI, it will be resolved relative to the\nTEI Publisher endpoint.\n\nThe JSON data returned by the endpoint should be an object with two properties:\n\n* `count`: the overall number of rows available on the server\n* `results`: an array containing each record as an object\n\nThe parameters send to the server are as follows:\n\n\nParameter | Description\n---------|----------\nlimit | number of records to return for each page\nstart | start offset from which to return records\norder | the id of the column to sort by\ndir | sort direction: either 'asc' or 'desc'\nsearch | an optional search string entered by the user\n\nTable columns are configured via nested `<pb-table-column>` elements:\n\n```html\n<pb-table-column label=\"Name\" property=\"name\" sort width=\"33%\"></pb-table-column>\n<pb-table-column label=\"Born\" property=\"birth\"></pb-table-column>\n<pb-table-column label=\"Died\" property=\"death\"></pb-table-column>\n```",
|
|
8987
|
+
"attributes": [
|
|
8988
|
+
{
|
|
8989
|
+
"name": "source",
|
|
8990
|
+
"description": "URI of the server-side endpoint to retrieve data from.\nRelative URIs are resolved relative to the configured TEI Publisher endpoint.",
|
|
8991
|
+
"type": "string"
|
|
8992
|
+
},
|
|
8993
|
+
{
|
|
8994
|
+
"name": "css-path",
|
|
8995
|
+
"description": "Path to the gridjs theme CSS files.",
|
|
8996
|
+
"type": "string",
|
|
8997
|
+
"default": "\"../css/gridjs\""
|
|
8998
|
+
},
|
|
8999
|
+
{
|
|
9000
|
+
"name": "resizable",
|
|
9001
|
+
"description": "If specified, columns (without a fixed width) will be resizable.",
|
|
9002
|
+
"type": "boolean",
|
|
9003
|
+
"default": "false"
|
|
9004
|
+
},
|
|
9005
|
+
{
|
|
9006
|
+
"name": "search",
|
|
9007
|
+
"description": "If specified, enable server-side search.",
|
|
9008
|
+
"type": "boolean",
|
|
9009
|
+
"default": "false"
|
|
9010
|
+
},
|
|
9011
|
+
{
|
|
9012
|
+
"name": "subscribe",
|
|
9013
|
+
"description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
|
|
9014
|
+
"type": "string"
|
|
9015
|
+
},
|
|
9016
|
+
{
|
|
9017
|
+
"name": "subscribe-config",
|
|
9018
|
+
"description": "Configuration object to define a channel/event mapping. Every property\nin the object is interpreted as the name of a channel and its value should\nbe an array of event names to listen to.",
|
|
9019
|
+
"type": "object"
|
|
9020
|
+
},
|
|
9021
|
+
{
|
|
9022
|
+
"name": "emit",
|
|
9023
|
+
"description": "The name of the channel to send events to.",
|
|
9024
|
+
"type": "string"
|
|
9025
|
+
},
|
|
9026
|
+
{
|
|
9027
|
+
"name": "emit-config",
|
|
9028
|
+
"description": "Configuration object to define a channel/event mapping. Every property\nin the object is interpreted as the name of a channel and its value should\nbe an array of event names to be dispatched.",
|
|
9029
|
+
"type": "object"
|
|
9030
|
+
},
|
|
9031
|
+
{
|
|
9032
|
+
"name": "wait-for",
|
|
9033
|
+
"description": "A selector pointing to other components this component depends on.\nWhen method `wait` is called, it will wait until all referenced\ncomponents signal with a `pb-ready` event that they are ready and listening\nto events.",
|
|
9034
|
+
"type": "string"
|
|
9035
|
+
},
|
|
9036
|
+
{
|
|
9037
|
+
"name": "disabled",
|
|
9038
|
+
"description": "Common property to disable the functionality associated with a component.\n`pb-highlight` and `pb-popover` react to this.",
|
|
9039
|
+
"type": "boolean",
|
|
9040
|
+
"default": "false"
|
|
9041
|
+
}
|
|
9042
|
+
],
|
|
9043
|
+
"properties": [
|
|
9044
|
+
{
|
|
9045
|
+
"name": "source",
|
|
9046
|
+
"attribute": "source",
|
|
9047
|
+
"description": "URI of the server-side endpoint to retrieve data from.\nRelative URIs are resolved relative to the configured TEI Publisher endpoint.",
|
|
9048
|
+
"type": "string"
|
|
9049
|
+
},
|
|
9050
|
+
{
|
|
9051
|
+
"name": "cssPath",
|
|
9052
|
+
"attribute": "css-path",
|
|
9053
|
+
"description": "Path to the gridjs theme CSS files.",
|
|
9054
|
+
"type": "string",
|
|
9055
|
+
"default": "\"../css/gridjs\""
|
|
9056
|
+
},
|
|
9057
|
+
{
|
|
9058
|
+
"name": "resizable",
|
|
9059
|
+
"attribute": "resizable",
|
|
9060
|
+
"description": "If specified, columns (without a fixed width) will be resizable.",
|
|
9061
|
+
"type": "boolean",
|
|
9062
|
+
"default": "false"
|
|
9063
|
+
},
|
|
9064
|
+
{
|
|
9065
|
+
"name": "search",
|
|
9066
|
+
"attribute": "search",
|
|
9067
|
+
"description": "If specified, enable server-side search.",
|
|
9068
|
+
"type": "boolean",
|
|
9069
|
+
"default": "false"
|
|
9070
|
+
},
|
|
9071
|
+
{
|
|
9072
|
+
"name": "subscribe",
|
|
9073
|
+
"attribute": "subscribe",
|
|
9074
|
+
"description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
|
|
9075
|
+
"type": "string"
|
|
9076
|
+
},
|
|
9077
|
+
{
|
|
9078
|
+
"name": "subscribeConfig",
|
|
9079
|
+
"attribute": "subscribe-config",
|
|
9080
|
+
"description": "Configuration object to define a channel/event mapping. Every property\nin the object is interpreted as the name of a channel and its value should\nbe an array of event names to listen to.",
|
|
9081
|
+
"type": "object"
|
|
9082
|
+
},
|
|
9083
|
+
{
|
|
9084
|
+
"name": "emit",
|
|
9085
|
+
"attribute": "emit",
|
|
9086
|
+
"description": "The name of the channel to send events to.",
|
|
9087
|
+
"type": "string"
|
|
9088
|
+
},
|
|
9089
|
+
{
|
|
9090
|
+
"name": "emitConfig",
|
|
9091
|
+
"attribute": "emit-config",
|
|
9092
|
+
"description": "Configuration object to define a channel/event mapping. Every property\nin the object is interpreted as the name of a channel and its value should\nbe an array of event names to be dispatched.",
|
|
9093
|
+
"type": "object"
|
|
9094
|
+
},
|
|
9095
|
+
{
|
|
9096
|
+
"name": "waitFor",
|
|
9097
|
+
"attribute": "wait-for",
|
|
9098
|
+
"description": "A selector pointing to other components this component depends on.\nWhen method `wait` is called, it will wait until all referenced\ncomponents signal with a `pb-ready` event that they are ready and listening\nto events.",
|
|
9099
|
+
"type": "string"
|
|
9100
|
+
},
|
|
9101
|
+
{
|
|
9102
|
+
"name": "disabled",
|
|
9103
|
+
"attribute": "disabled",
|
|
9104
|
+
"description": "Common property to disable the functionality associated with a component.\n`pb-highlight` and `pb-popover` react to this.",
|
|
9105
|
+
"type": "boolean",
|
|
9106
|
+
"default": "false"
|
|
9107
|
+
}
|
|
9108
|
+
]
|
|
9109
|
+
},
|
|
8926
9110
|
{
|
|
8927
9111
|
"name": "pb-tabs",
|
|
8928
9112
|
"path": "./src/pb-tabs.js",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teipublisher/pb-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.27.0",
|
|
4
4
|
"description": "Collection of webcomponents underlying TEI Publisher",
|
|
5
5
|
"repository": "https://github.com/eeditiones/tei-publisher-components.git",
|
|
6
6
|
"main": "index.html",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"@webcomponents/webcomponentsjs": "latest",
|
|
69
69
|
"animejs": "^3.2.0",
|
|
70
70
|
"codemirror": "^5.58.1",
|
|
71
|
+
"gridjs": "^5.0.2",
|
|
71
72
|
"hotkeys-js": "^3.8.1",
|
|
72
73
|
"i18next": "19.8.1",
|
|
73
74
|
"i18next-browser-languagedetector": "^6.0.1",
|
package/pb-elements.json
CHANGED
|
@@ -8923,6 +8923,190 @@
|
|
|
8923
8923
|
}
|
|
8924
8924
|
]
|
|
8925
8925
|
},
|
|
8926
|
+
{
|
|
8927
|
+
"name": "pb-table-column",
|
|
8928
|
+
"path": "./src/pb-table-column.js",
|
|
8929
|
+
"description": "Defines a column within `pb-table-grid`.",
|
|
8930
|
+
"attributes": [
|
|
8931
|
+
{
|
|
8932
|
+
"name": "label",
|
|
8933
|
+
"description": "Column heading to display",
|
|
8934
|
+
"type": "string",
|
|
8935
|
+
"default": "\"no-label\""
|
|
8936
|
+
},
|
|
8937
|
+
{
|
|
8938
|
+
"name": "property",
|
|
8939
|
+
"description": "Name of the JSON property containing the data",
|
|
8940
|
+
"type": "string"
|
|
8941
|
+
},
|
|
8942
|
+
{
|
|
8943
|
+
"name": "sort",
|
|
8944
|
+
"description": "Should the column support sorting?",
|
|
8945
|
+
"type": "boolean",
|
|
8946
|
+
"default": "false"
|
|
8947
|
+
},
|
|
8948
|
+
{
|
|
8949
|
+
"name": "width",
|
|
8950
|
+
"description": "Optional fixed width of the column (e.g. '200px' or '30%')",
|
|
8951
|
+
"type": "string"
|
|
8952
|
+
}
|
|
8953
|
+
],
|
|
8954
|
+
"properties": [
|
|
8955
|
+
{
|
|
8956
|
+
"name": "label",
|
|
8957
|
+
"attribute": "label",
|
|
8958
|
+
"description": "Column heading to display",
|
|
8959
|
+
"type": "string",
|
|
8960
|
+
"default": "\"no-label\""
|
|
8961
|
+
},
|
|
8962
|
+
{
|
|
8963
|
+
"name": "property",
|
|
8964
|
+
"attribute": "property",
|
|
8965
|
+
"description": "Name of the JSON property containing the data",
|
|
8966
|
+
"type": "string"
|
|
8967
|
+
},
|
|
8968
|
+
{
|
|
8969
|
+
"name": "sort",
|
|
8970
|
+
"attribute": "sort",
|
|
8971
|
+
"description": "Should the column support sorting?",
|
|
8972
|
+
"type": "boolean",
|
|
8973
|
+
"default": "false"
|
|
8974
|
+
},
|
|
8975
|
+
{
|
|
8976
|
+
"name": "width",
|
|
8977
|
+
"attribute": "width",
|
|
8978
|
+
"description": "Optional fixed width of the column (e.g. '200px' or '30%')",
|
|
8979
|
+
"type": "string"
|
|
8980
|
+
}
|
|
8981
|
+
]
|
|
8982
|
+
},
|
|
8983
|
+
{
|
|
8984
|
+
"name": "pb-table-grid",
|
|
8985
|
+
"path": "./src/pb-table-grid.js",
|
|
8986
|
+
"description": "A table grid based on [gridjs](https://gridjs.io/), which loads its data from a server endpoint\nspecified in `source`. If `source` is a relative URI, it will be resolved relative to the\nTEI Publisher endpoint.\n\nThe JSON data returned by the endpoint should be an object with two properties:\n\n* `count`: the overall number of rows available on the server\n* `results`: an array containing each record as an object\n\nThe parameters send to the server are as follows:\n\n\nParameter | Description\n---------|----------\nlimit | number of records to return for each page\nstart | start offset from which to return records\norder | the id of the column to sort by\ndir | sort direction: either 'asc' or 'desc'\nsearch | an optional search string entered by the user\n\nTable columns are configured via nested `<pb-table-column>` elements:\n\n```html\n<pb-table-column label=\"Name\" property=\"name\" sort width=\"33%\"></pb-table-column>\n<pb-table-column label=\"Born\" property=\"birth\"></pb-table-column>\n<pb-table-column label=\"Died\" property=\"death\"></pb-table-column>\n```",
|
|
8987
|
+
"attributes": [
|
|
8988
|
+
{
|
|
8989
|
+
"name": "source",
|
|
8990
|
+
"description": "URI of the server-side endpoint to retrieve data from.\nRelative URIs are resolved relative to the configured TEI Publisher endpoint.",
|
|
8991
|
+
"type": "string"
|
|
8992
|
+
},
|
|
8993
|
+
{
|
|
8994
|
+
"name": "css-path",
|
|
8995
|
+
"description": "Path to the gridjs theme CSS files.",
|
|
8996
|
+
"type": "string",
|
|
8997
|
+
"default": "\"../css/gridjs\""
|
|
8998
|
+
},
|
|
8999
|
+
{
|
|
9000
|
+
"name": "resizable",
|
|
9001
|
+
"description": "If specified, columns (without a fixed width) will be resizable.",
|
|
9002
|
+
"type": "boolean",
|
|
9003
|
+
"default": "false"
|
|
9004
|
+
},
|
|
9005
|
+
{
|
|
9006
|
+
"name": "search",
|
|
9007
|
+
"description": "If specified, enable server-side search.",
|
|
9008
|
+
"type": "boolean",
|
|
9009
|
+
"default": "false"
|
|
9010
|
+
},
|
|
9011
|
+
{
|
|
9012
|
+
"name": "subscribe",
|
|
9013
|
+
"description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
|
|
9014
|
+
"type": "string"
|
|
9015
|
+
},
|
|
9016
|
+
{
|
|
9017
|
+
"name": "subscribe-config",
|
|
9018
|
+
"description": "Configuration object to define a channel/event mapping. Every property\nin the object is interpreted as the name of a channel and its value should\nbe an array of event names to listen to.",
|
|
9019
|
+
"type": "object"
|
|
9020
|
+
},
|
|
9021
|
+
{
|
|
9022
|
+
"name": "emit",
|
|
9023
|
+
"description": "The name of the channel to send events to.",
|
|
9024
|
+
"type": "string"
|
|
9025
|
+
},
|
|
9026
|
+
{
|
|
9027
|
+
"name": "emit-config",
|
|
9028
|
+
"description": "Configuration object to define a channel/event mapping. Every property\nin the object is interpreted as the name of a channel and its value should\nbe an array of event names to be dispatched.",
|
|
9029
|
+
"type": "object"
|
|
9030
|
+
},
|
|
9031
|
+
{
|
|
9032
|
+
"name": "wait-for",
|
|
9033
|
+
"description": "A selector pointing to other components this component depends on.\nWhen method `wait` is called, it will wait until all referenced\ncomponents signal with a `pb-ready` event that they are ready and listening\nto events.",
|
|
9034
|
+
"type": "string"
|
|
9035
|
+
},
|
|
9036
|
+
{
|
|
9037
|
+
"name": "disabled",
|
|
9038
|
+
"description": "Common property to disable the functionality associated with a component.\n`pb-highlight` and `pb-popover` react to this.",
|
|
9039
|
+
"type": "boolean",
|
|
9040
|
+
"default": "false"
|
|
9041
|
+
}
|
|
9042
|
+
],
|
|
9043
|
+
"properties": [
|
|
9044
|
+
{
|
|
9045
|
+
"name": "source",
|
|
9046
|
+
"attribute": "source",
|
|
9047
|
+
"description": "URI of the server-side endpoint to retrieve data from.\nRelative URIs are resolved relative to the configured TEI Publisher endpoint.",
|
|
9048
|
+
"type": "string"
|
|
9049
|
+
},
|
|
9050
|
+
{
|
|
9051
|
+
"name": "cssPath",
|
|
9052
|
+
"attribute": "css-path",
|
|
9053
|
+
"description": "Path to the gridjs theme CSS files.",
|
|
9054
|
+
"type": "string",
|
|
9055
|
+
"default": "\"../css/gridjs\""
|
|
9056
|
+
},
|
|
9057
|
+
{
|
|
9058
|
+
"name": "resizable",
|
|
9059
|
+
"attribute": "resizable",
|
|
9060
|
+
"description": "If specified, columns (without a fixed width) will be resizable.",
|
|
9061
|
+
"type": "boolean",
|
|
9062
|
+
"default": "false"
|
|
9063
|
+
},
|
|
9064
|
+
{
|
|
9065
|
+
"name": "search",
|
|
9066
|
+
"attribute": "search",
|
|
9067
|
+
"description": "If specified, enable server-side search.",
|
|
9068
|
+
"type": "boolean",
|
|
9069
|
+
"default": "false"
|
|
9070
|
+
},
|
|
9071
|
+
{
|
|
9072
|
+
"name": "subscribe",
|
|
9073
|
+
"attribute": "subscribe",
|
|
9074
|
+
"description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
|
|
9075
|
+
"type": "string"
|
|
9076
|
+
},
|
|
9077
|
+
{
|
|
9078
|
+
"name": "subscribeConfig",
|
|
9079
|
+
"attribute": "subscribe-config",
|
|
9080
|
+
"description": "Configuration object to define a channel/event mapping. Every property\nin the object is interpreted as the name of a channel and its value should\nbe an array of event names to listen to.",
|
|
9081
|
+
"type": "object"
|
|
9082
|
+
},
|
|
9083
|
+
{
|
|
9084
|
+
"name": "emit",
|
|
9085
|
+
"attribute": "emit",
|
|
9086
|
+
"description": "The name of the channel to send events to.",
|
|
9087
|
+
"type": "string"
|
|
9088
|
+
},
|
|
9089
|
+
{
|
|
9090
|
+
"name": "emitConfig",
|
|
9091
|
+
"attribute": "emit-config",
|
|
9092
|
+
"description": "Configuration object to define a channel/event mapping. Every property\nin the object is interpreted as the name of a channel and its value should\nbe an array of event names to be dispatched.",
|
|
9093
|
+
"type": "object"
|
|
9094
|
+
},
|
|
9095
|
+
{
|
|
9096
|
+
"name": "waitFor",
|
|
9097
|
+
"attribute": "wait-for",
|
|
9098
|
+
"description": "A selector pointing to other components this component depends on.\nWhen method `wait` is called, it will wait until all referenced\ncomponents signal with a `pb-ready` event that they are ready and listening\nto events.",
|
|
9099
|
+
"type": "string"
|
|
9100
|
+
},
|
|
9101
|
+
{
|
|
9102
|
+
"name": "disabled",
|
|
9103
|
+
"attribute": "disabled",
|
|
9104
|
+
"description": "Common property to disable the functionality associated with a component.\n`pb-highlight` and `pb-popover` react to this.",
|
|
9105
|
+
"type": "boolean",
|
|
9106
|
+
"default": "false"
|
|
9107
|
+
}
|
|
9108
|
+
]
|
|
9109
|
+
},
|
|
8926
9110
|
{
|
|
8927
9111
|
"name": "pb-tabs",
|
|
8928
9112
|
"path": "./src/pb-tabs.js",
|
package/src/pb-components.js
CHANGED
|
@@ -56,6 +56,7 @@ import './pb-authority-lookup.js';
|
|
|
56
56
|
import './pb-message.js';
|
|
57
57
|
import './pb-blacklab-results.js';
|
|
58
58
|
import './pb-blacklab-highlight.js';
|
|
59
|
+
import './pb-table-grid.js';
|
|
59
60
|
|
|
60
61
|
import '@polymer/iron-icons/editor-icons';
|
|
61
62
|
import '@polymer/iron-icons/social-icons';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { LitElement } from 'lit-element';
|
|
2
|
+
import { html } from "gridjs";
|
|
3
|
+
import './pb-popover.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Defines a column within `pb-table-grid`.
|
|
7
|
+
*/
|
|
8
|
+
export class PbTableColumn extends LitElement {
|
|
9
|
+
static get properties() {
|
|
10
|
+
return {
|
|
11
|
+
/**
|
|
12
|
+
* Column heading to display
|
|
13
|
+
*/
|
|
14
|
+
label: {
|
|
15
|
+
type: String
|
|
16
|
+
},
|
|
17
|
+
/**
|
|
18
|
+
* Name of the JSON property containing the data
|
|
19
|
+
*/
|
|
20
|
+
property: {
|
|
21
|
+
type: String
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
* Should the column support sorting?
|
|
25
|
+
*/
|
|
26
|
+
sort: {
|
|
27
|
+
type: Boolean
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* Optional fixed width of the column (e.g. '200px' or '30%')
|
|
31
|
+
*/
|
|
32
|
+
width: {
|
|
33
|
+
type: String
|
|
34
|
+
},
|
|
35
|
+
...super.properties
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
constructor() {
|
|
40
|
+
super();
|
|
41
|
+
this.label = 'no-label';
|
|
42
|
+
this.property = null;
|
|
43
|
+
this.sort = false;
|
|
44
|
+
this.width = null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
super.connectedCallback();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
data() {
|
|
52
|
+
const config = {
|
|
53
|
+
name: this.label,
|
|
54
|
+
sort: { enabled: this.sort },
|
|
55
|
+
formatter: (cell) => html(cell)
|
|
56
|
+
};
|
|
57
|
+
if (this.property) {
|
|
58
|
+
config.id = this.property;
|
|
59
|
+
}
|
|
60
|
+
if (this.width) {
|
|
61
|
+
config.width = this.width;
|
|
62
|
+
}
|
|
63
|
+
return config;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
customElements.define('pb-table-column', PbTableColumn);
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit-element';
|
|
2
|
+
import { Grid } from "gridjs";
|
|
3
|
+
import { pbMixin } from './pb-mixin.js';
|
|
4
|
+
import { resolveURL } from './utils.js';
|
|
5
|
+
import '@polymer/paper-input/paper-input';
|
|
6
|
+
import '@polymer/iron-icons';
|
|
7
|
+
import '@polymer/iron-form';
|
|
8
|
+
import '@polymer/paper-icon-button';
|
|
9
|
+
import './pb-table-column.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A table grid based on [gridjs](https://gridjs.io/), which loads its data from a server endpoint
|
|
13
|
+
* specified in `source`. If `source` is a relative URI, it will be resolved relative to the
|
|
14
|
+
* TEI Publisher endpoint.
|
|
15
|
+
*
|
|
16
|
+
* The JSON data returned by the endpoint should be an object with two properties:
|
|
17
|
+
*
|
|
18
|
+
* * `count`: the overall number of rows available on the server
|
|
19
|
+
* * `results`: an array containing each record as an object
|
|
20
|
+
*
|
|
21
|
+
* The parameters send to the server are as follows:
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* Parameter | Description
|
|
25
|
+
* ---------|----------
|
|
26
|
+
* limit | number of records to return for each page
|
|
27
|
+
* start | start offset from which to return records
|
|
28
|
+
* order | the id of the column to sort by
|
|
29
|
+
* dir | sort direction: either 'asc' or 'desc'
|
|
30
|
+
* search | an optional search string entered by the user
|
|
31
|
+
*
|
|
32
|
+
* Table columns are configured via nested `<pb-table-column>` elements:
|
|
33
|
+
*
|
|
34
|
+
* ```html
|
|
35
|
+
* <pb-table-column label="Name" property="name" sort width="33%"></pb-table-column>
|
|
36
|
+
* <pb-table-column label="Born" property="birth"></pb-table-column>
|
|
37
|
+
* <pb-table-column label="Died" property="death"></pb-table-column>
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export class PbTableGrid extends pbMixin(LitElement) {
|
|
41
|
+
static get properties() {
|
|
42
|
+
return {
|
|
43
|
+
/**
|
|
44
|
+
* URI of the server-side endpoint to retrieve data from.
|
|
45
|
+
* Relative URIs are resolved relative to the configured TEI Publisher endpoint.
|
|
46
|
+
*/
|
|
47
|
+
source: {
|
|
48
|
+
type: String
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Path to the gridjs theme CSS files.
|
|
52
|
+
*/
|
|
53
|
+
cssPath: {
|
|
54
|
+
type: String,
|
|
55
|
+
attribute: 'css-path'
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* If specified, columns (without a fixed width) will be resizable.
|
|
59
|
+
*/
|
|
60
|
+
resizable: {
|
|
61
|
+
type: Boolean
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* If specified, enable server-side search.
|
|
65
|
+
*/
|
|
66
|
+
search: {
|
|
67
|
+
type: Boolean
|
|
68
|
+
},
|
|
69
|
+
_params: {
|
|
70
|
+
type: Object
|
|
71
|
+
},
|
|
72
|
+
...super.properties
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
constructor() {
|
|
77
|
+
super();
|
|
78
|
+
this.cssPath = '../css/gridjs';
|
|
79
|
+
this._params = {};
|
|
80
|
+
this.resizable = false;
|
|
81
|
+
this.search = false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
connectedCallback() {
|
|
85
|
+
super.connectedCallback();
|
|
86
|
+
|
|
87
|
+
this.subscribeTo('pb-search-resubmit', (ev) => {
|
|
88
|
+
this._params = Object.assign({}, ev.detail.params);
|
|
89
|
+
this._submit();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
window.addEventListener('popstate', (ev) => {
|
|
93
|
+
this._params = ev.state;
|
|
94
|
+
this._submit();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
firstUpdated() {
|
|
99
|
+
const table = this.shadowRoot.getElementById('table');
|
|
100
|
+
|
|
101
|
+
const pbColumns = this.querySelectorAll('pb-table-column');
|
|
102
|
+
const columns = [];
|
|
103
|
+
pbColumns.forEach((column) => columns.push(column.data()));
|
|
104
|
+
|
|
105
|
+
PbTableGrid.waitOnce('pb-page-ready', () => {
|
|
106
|
+
this._params = this.getParameters();
|
|
107
|
+
const url = this.toAbsoluteURL(this.source);
|
|
108
|
+
const config = {
|
|
109
|
+
columns,
|
|
110
|
+
resizable: this.resizable,
|
|
111
|
+
server: {
|
|
112
|
+
url,
|
|
113
|
+
then: data => data.results,
|
|
114
|
+
total: data => data.count
|
|
115
|
+
},
|
|
116
|
+
sort: {
|
|
117
|
+
multiColumn: false,
|
|
118
|
+
server: {
|
|
119
|
+
url: (prev, cols) => {
|
|
120
|
+
if (!cols.length) return prev;
|
|
121
|
+
const col = cols[0];
|
|
122
|
+
return `${prev}${prev.indexOf('?') > -1 ? '&' : '?'}order=${columns[col.index].id}&dir=${col.direction === 1 ? 'asc' : 'desc'}`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
pagination: {
|
|
127
|
+
enabled: true,
|
|
128
|
+
limit: 10,
|
|
129
|
+
server: {
|
|
130
|
+
url: (prev, page, limit) => {
|
|
131
|
+
const form = this.shadowRoot.getElementById('form');
|
|
132
|
+
if (form) {
|
|
133
|
+
Object.assign(this._params, form.serializeForm());
|
|
134
|
+
}
|
|
135
|
+
this._params.limit = limit;
|
|
136
|
+
this._params.start = page * limit;
|
|
137
|
+
this.setParameters(this._params);
|
|
138
|
+
this.pushHistory('grid', this._params);
|
|
139
|
+
|
|
140
|
+
return `${prev}${prev.indexOf('?') > -1 ? '&' : '?'}${new URLSearchParams(this._params).toString()}`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
this.grid = new Grid(config);
|
|
146
|
+
this.grid.on('load', () => {
|
|
147
|
+
this.emitTo('pb-results-received', {
|
|
148
|
+
"params": this._params
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
this.grid.render(table);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
_submit() {
|
|
157
|
+
this.grid.forceRender();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
render() {
|
|
161
|
+
const themes = resolveURL(this.cssPath);
|
|
162
|
+
return html`
|
|
163
|
+
<link href="${themes}/mermaid.min.css" rel="stylesheet">
|
|
164
|
+
${
|
|
165
|
+
this.search ? html`
|
|
166
|
+
<iron-form id="form">
|
|
167
|
+
<form action="">
|
|
168
|
+
<paper-input id="search" name="search" label="Search" @keyup="${(e) => e.keyCode == 13 ? this._submit() : null}">
|
|
169
|
+
<paper-icon-button icon="search" @click="${this._submit}" slot="suffix"></paper-icon-button>
|
|
170
|
+
</paper-input>
|
|
171
|
+
</form>
|
|
172
|
+
</iron-form>
|
|
173
|
+
` : null
|
|
174
|
+
}
|
|
175
|
+
<div id="table"></div>
|
|
176
|
+
`;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static get styles() {
|
|
180
|
+
return css`
|
|
181
|
+
:host {
|
|
182
|
+
display: block;
|
|
183
|
+
}
|
|
184
|
+
button {
|
|
185
|
+
border: 0;
|
|
186
|
+
}
|
|
187
|
+
`;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
customElements.define('pb-table-grid', PbTableGrid);
|