@wordpress/views 1.22.0 → 1.23.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 +2 -0
- package/README.md +20 -20
- package/build/use-view-config.cjs.map +2 -2
- package/build-module/use-view-config.mjs.map +2 -2
- package/package.json +9 -10
- package/src/use-view-config.ts +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -4,10 +4,10 @@ A lightweight package for managing DataViews view state with persistence using W
|
|
|
4
4
|
|
|
5
5
|
The `@wordpress/views` package provides:
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
7
|
+
- **Persistence**: Automatically saves and restores DataViews state using `@wordpress/preferences`
|
|
8
|
+
- **View Modification Detection**: Tracks when views differ from their default state
|
|
9
|
+
- **Reset Functionality**: Simple reset to default view capability
|
|
10
|
+
- **Clean Integration**: Drop-in replacement for manual view state management
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -29,18 +29,18 @@ Resolves the same layers `useView` does, so a route loader and the hook that tak
|
|
|
29
29
|
|
|
30
30
|
_Parameters_
|
|
31
31
|
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
32
|
+
- _config_ `ViewConfig`: Configuration object for loading the view.
|
|
33
|
+
- _config.kind_ `ViewConfig`: Entity kind (e.g., 'postType', 'taxonomy', 'root').
|
|
34
|
+
- _config.name_ `ViewConfig`: Specific entity name.
|
|
35
|
+
- _config.slug_ `ViewConfig`: View identifier.
|
|
36
|
+
- _config.defaultView_ `ViewConfig`: Default view configuration.
|
|
37
|
+
- _config.defaultLayouts_ `ViewConfig`: Default layout configurations keyed by layout type.
|
|
38
|
+
- _config.activeViewOverrides_ `ViewConfig`: View overrides applied on top but never persisted.
|
|
39
|
+
- _config.queryParams_ `ViewConfig`: Object with `page` and/or `search` from URL.
|
|
40
40
|
|
|
41
41
|
_Returns_
|
|
42
42
|
|
|
43
|
-
-
|
|
43
|
+
- Promise resolving to the loaded view object.
|
|
44
44
|
|
|
45
45
|
### useView
|
|
46
46
|
|
|
@@ -50,11 +50,11 @@ Only the properties the user actually modified are persisted: every other proper
|
|
|
50
50
|
|
|
51
51
|
_Parameters_
|
|
52
52
|
|
|
53
|
-
-
|
|
53
|
+
- _config_ `ViewConfig`: Configuration object for loading the view.
|
|
54
54
|
|
|
55
55
|
_Returns_
|
|
56
56
|
|
|
57
|
-
-
|
|
57
|
+
- `UseViewReturn`: Object with current view, modification state, and update functions.
|
|
58
58
|
|
|
59
59
|
### useViewConfig
|
|
60
60
|
|
|
@@ -62,13 +62,13 @@ A hook that retrieves the view configuration for a given entity from the core da
|
|
|
62
62
|
|
|
63
63
|
_Parameters_
|
|
64
64
|
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
65
|
+
- _params_ `Object`:
|
|
66
|
+
- _params.kind_ `string`: The kind of the entity.
|
|
67
|
+
- _params.name_ `string`: The name of the entity.
|
|
68
|
+
- _params.fields_ `[?(string|string[])]`: Subset of top-level config properties to request, as an array or a comma-separated string (mapped to the REST API `_fields` parameter). When omitted, the full config is requested.
|
|
69
69
|
|
|
70
70
|
_Returns_
|
|
71
71
|
|
|
72
|
-
-
|
|
72
|
+
- `Object`: An object containing the `default_view`, `default_layouts`, `view_list`, and `form` configuration for the entity.
|
|
73
73
|
|
|
74
74
|
<!-- END TOKEN(Autogenerated API docs) -->
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/use-view-config.ts"],
|
|
4
|
-
"sourcesContent": ["import { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { View, SupportedLayouts, Form } from '@wordpress/dataviews';\nimport { unlock } from './lock-unlock';\n\n/**\n * A hook that retrieves the view configuration for a given entity\n * from the core data store.\n *\n * @param {Object} params\n * @param {string} params.kind The kind of the entity.\n * @param {string} params.name The name of the entity.\n * @param {?(string|string[])} [params.fields] Subset of top-level config\n * properties to request, as an array\n * or a comma-separated string\n * (mapped to the REST API `_fields`\n * parameter). When omitted, the full\n * config is requested.\n * @return {Object} An object containing the `default_view`, `default_layouts`, `view_list`, and `form` configuration for the entity.\n */\nexport function useViewConfig( {\n\tkind,\n\tname,\n\tfields,\n}: {\n\tkind: string;\n\tname: string;\n\tfields?: string | string[];\n} ): {\n\tdefault_view: View | undefined;\n\tdefault_layouts: SupportedLayouts | undefined;\n\tview_list: Array< any > | undefined;\n\tform: Form | undefined;\n} {\n\t// Sort fields so the cache key is independent of the order callers list\n\t// them; `['title','author']` and `['author','title']` request the same data.\n\tconst fieldList = Array.isArray( fields ) ? fields : fields?.split( ',' );\n\tconst fieldsKey = fieldList\n\t\t? [ ...fieldList ].sort().join( ',' )\n\t\t: undefined;\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\treturn unlock( select( coreStore ) ).getViewConfig(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tfieldsKey\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tfields: fieldsKey,\n\t\t\t\t\t
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0B;AAC1B,uBAAmC;AAEnC,yBAAuB;AAiBhB,SAAS,cAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACD,GASE;AAGD,QAAM,YAAY,MAAM,QAAS,MAAO,IAAI,SAAS,QAAQ,MAAO,GAAI;AACxE,QAAM,YAAY,YACf,CAAE,GAAG,SAAU,EAAE,KAAK,EAAE,KAAM,GAAI,IAClC;AACH,aAAO;AAAA,IACN,CAAE,WAAY;AACb,iBAAO,2BAAQ,OAAQ,iBAAAA,KAAU,CAAE,EAAE;AAAA,QACpC;AAAA,QACA;AAAA,QACA,YACG;AAAA,UACA,QAAQ;AAAA,
|
|
4
|
+
"sourcesContent": ["import { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { View, SupportedLayouts, Form } from '@wordpress/dataviews';\nimport { unlock } from './lock-unlock';\n\n/**\n * A hook that retrieves the view configuration for a given entity\n * from the core data store.\n *\n * @param {Object} params\n * @param {string} params.kind The kind of the entity.\n * @param {string} params.name The name of the entity.\n * @param {?(string|string[])} [params.fields] Subset of top-level config\n * properties to request, as an array\n * or a comma-separated string\n * (mapped to the REST API `_fields`\n * parameter). When omitted, the full\n * config is requested.\n * @return {Object} An object containing the `default_view`, `default_layouts`, `view_list`, and `form` configuration for the entity.\n */\nexport function useViewConfig( {\n\tkind,\n\tname,\n\tfields,\n}: {\n\tkind: string;\n\tname: string;\n\tfields?: string | string[];\n} ): {\n\tdefault_view: View | undefined;\n\tdefault_layouts: SupportedLayouts | undefined;\n\tview_list: Array< any > | undefined;\n\tform: Form | undefined;\n} {\n\t// Sort fields so the cache key is independent of the order callers list\n\t// them; `['title','author']` and `['author','title']` request the same data.\n\tconst fieldList = Array.isArray( fields ) ? fields : fields?.split( ',' );\n\tconst fieldsKey = fieldList\n\t\t? [ ...fieldList ].sort().join( ',' )\n\t\t: undefined;\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\treturn unlock( select( coreStore ) ).getViewConfig(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tfieldsKey\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tfields: fieldsKey,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined\n\t\t\t);\n\t\t},\n\t\t[ kind, name, fieldsKey ]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0B;AAC1B,uBAAmC;AAEnC,yBAAuB;AAiBhB,SAAS,cAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACD,GASE;AAGD,QAAM,YAAY,MAAM,QAAS,MAAO,IAAI,SAAS,QAAQ,MAAO,GAAI;AACxE,QAAM,YAAY,YACf,CAAE,GAAG,SAAU,EAAE,KAAK,EAAE,KAAM,GAAI,IAClC;AACH,aAAO;AAAA,IACN,CAAE,WAAY;AACb,iBAAO,2BAAQ,OAAQ,iBAAAA,KAAU,CAAE,EAAE;AAAA,QACpC;AAAA,QACA;AAAA,QACA,YACG;AAAA,UACA,QAAQ;AAAA,QACT,IACC;AAAA,MACJ;AAAA,IACD;AAAA,IACA,CAAE,MAAM,MAAM,SAAU;AAAA,EACzB;AACD;",
|
|
6
6
|
"names": ["coreStore"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/use-view-config.ts"],
|
|
4
|
-
"sourcesContent": ["import { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { View, SupportedLayouts, Form } from '@wordpress/dataviews';\nimport { unlock } from './lock-unlock';\n\n/**\n * A hook that retrieves the view configuration for a given entity\n * from the core data store.\n *\n * @param {Object} params\n * @param {string} params.kind The kind of the entity.\n * @param {string} params.name The name of the entity.\n * @param {?(string|string[])} [params.fields] Subset of top-level config\n * properties to request, as an array\n * or a comma-separated string\n * (mapped to the REST API `_fields`\n * parameter). When omitted, the full\n * config is requested.\n * @return {Object} An object containing the `default_view`, `default_layouts`, `view_list`, and `form` configuration for the entity.\n */\nexport function useViewConfig( {\n\tkind,\n\tname,\n\tfields,\n}: {\n\tkind: string;\n\tname: string;\n\tfields?: string | string[];\n} ): {\n\tdefault_view: View | undefined;\n\tdefault_layouts: SupportedLayouts | undefined;\n\tview_list: Array< any > | undefined;\n\tform: Form | undefined;\n} {\n\t// Sort fields so the cache key is independent of the order callers list\n\t// them; `['title','author']` and `['author','title']` request the same data.\n\tconst fieldList = Array.isArray( fields ) ? fields : fields?.split( ',' );\n\tconst fieldsKey = fieldList\n\t\t? [ ...fieldList ].sort().join( ',' )\n\t\t: undefined;\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\treturn unlock( select( coreStore ) ).getViewConfig(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tfieldsKey\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tfields: fieldsKey,\n\t\t\t\t\t
|
|
5
|
-
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AAEnC,SAAS,cAAc;AAiBhB,SAAS,cAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACD,GASE;AAGD,QAAM,YAAY,MAAM,QAAS,MAAO,IAAI,SAAS,QAAQ,MAAO,GAAI;AACxE,QAAM,YAAY,YACf,CAAE,GAAG,SAAU,EAAE,KAAK,EAAE,KAAM,GAAI,IAClC;AACH,SAAO;AAAA,IACN,CAAE,WAAY;AACb,aAAO,OAAQ,OAAQ,SAAU,CAAE,EAAE;AAAA,QACpC;AAAA,QACA;AAAA,QACA,YACG;AAAA,UACA,QAAQ;AAAA,
|
|
4
|
+
"sourcesContent": ["import { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { View, SupportedLayouts, Form } from '@wordpress/dataviews';\nimport { unlock } from './lock-unlock';\n\n/**\n * A hook that retrieves the view configuration for a given entity\n * from the core data store.\n *\n * @param {Object} params\n * @param {string} params.kind The kind of the entity.\n * @param {string} params.name The name of the entity.\n * @param {?(string|string[])} [params.fields] Subset of top-level config\n * properties to request, as an array\n * or a comma-separated string\n * (mapped to the REST API `_fields`\n * parameter). When omitted, the full\n * config is requested.\n * @return {Object} An object containing the `default_view`, `default_layouts`, `view_list`, and `form` configuration for the entity.\n */\nexport function useViewConfig( {\n\tkind,\n\tname,\n\tfields,\n}: {\n\tkind: string;\n\tname: string;\n\tfields?: string | string[];\n} ): {\n\tdefault_view: View | undefined;\n\tdefault_layouts: SupportedLayouts | undefined;\n\tview_list: Array< any > | undefined;\n\tform: Form | undefined;\n} {\n\t// Sort fields so the cache key is independent of the order callers list\n\t// them; `['title','author']` and `['author','title']` request the same data.\n\tconst fieldList = Array.isArray( fields ) ? fields : fields?.split( ',' );\n\tconst fieldsKey = fieldList\n\t\t? [ ...fieldList ].sort().join( ',' )\n\t\t: undefined;\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\treturn unlock( select( coreStore ) ).getViewConfig(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tfieldsKey\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tfields: fieldsKey,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined\n\t\t\t);\n\t\t},\n\t\t[ kind, name, fieldsKey ]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AAEnC,SAAS,cAAc;AAiBhB,SAAS,cAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACD,GASE;AAGD,QAAM,YAAY,MAAM,QAAS,MAAO,IAAI,SAAS,QAAQ,MAAO,GAAI;AACxE,QAAM,YAAY,YACf,CAAE,GAAG,SAAU,EAAE,KAAK,EAAE,KAAM,GAAI,IAClC;AACH,SAAO;AAAA,IACN,CAAE,WAAY;AACb,aAAO,OAAQ,OAAQ,SAAU,CAAE,EAAE;AAAA,QACpC;AAAA,QACA;AAAA,QACA,YACG;AAAA,UACA,QAAQ;AAAA,QACT,IACC;AAAA,MACJ;AAAA,IACD;AAAA,IACA,CAAE,MAAM,MAAM,SAAU;AAAA,EACzB;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/views",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "View persistence and management for WordPress DataViews.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
"url": "https://github.com/WordPress/gutenberg/issues"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": ">=18.12.0"
|
|
23
|
-
"npm": ">=8.19.2"
|
|
22
|
+
"node": ">=18.12.0"
|
|
24
23
|
},
|
|
25
24
|
"files": [
|
|
26
25
|
"src",
|
|
@@ -41,12 +40,12 @@
|
|
|
41
40
|
},
|
|
42
41
|
"types": "build-types",
|
|
43
42
|
"dependencies": {
|
|
44
|
-
"@wordpress/core-data": "^8.
|
|
45
|
-
"@wordpress/data": "^10.
|
|
46
|
-
"@wordpress/dataviews": "^19.
|
|
47
|
-
"@wordpress/element": "^8.
|
|
48
|
-
"@wordpress/preferences": "^4.
|
|
49
|
-
"@wordpress/private-apis": "^1.
|
|
43
|
+
"@wordpress/core-data": "^8.1.0",
|
|
44
|
+
"@wordpress/data": "^10.56.0",
|
|
45
|
+
"@wordpress/dataviews": "^19.1.0",
|
|
46
|
+
"@wordpress/element": "^8.8.0",
|
|
47
|
+
"@wordpress/preferences": "^4.56.0",
|
|
48
|
+
"@wordpress/private-apis": "^1.56.0",
|
|
50
49
|
"dequal": "^2.0.3"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
@@ -58,5 +57,5 @@
|
|
|
58
57
|
"publishConfig": {
|
|
59
58
|
"access": "public"
|
|
60
59
|
},
|
|
61
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "56d8058eda6e30c4cc8bfc37818fa6ed972f7dc2"
|
|
62
61
|
}
|