@wordpress/views 3.0.0 → 3.2.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/build/index.cjs +23 -34
- package/build/load-view.cjs +38 -53
- package/build/load-view.cjs.map +1 -7
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/preference-keys.cjs +16 -29
- package/build/preference-keys.cjs.map +1 -7
- package/build/resolve-view.cjs +177 -128
- package/build/resolve-view.cjs.map +1 -7
- package/build/types.cjs +4 -18
- package/build/use-view-config.cjs +35 -50
- package/build/use-view-config.cjs.map +1 -7
- package/build/use-view.cjs +83 -120
- package/build/use-view.cjs.map +1 -7
- package/build-module/index.mjs +1 -7
- package/build-module/load-view.mjs +32 -27
- package/build-module/load-view.mjs.map +1 -7
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/preference-keys.mjs +12 -5
- package/build-module/preference-keys.mjs.map +1 -7
- package/build-module/resolve-view.mjs +171 -102
- package/build-module/resolve-view.mjs.map +1 -7
- package/build-module/types.mjs +0 -1
- package/build-module/use-view-config.mjs +30 -25
- package/build-module/use-view-config.mjs.map +1 -7
- package/build-module/use-view.mjs +76 -97
- package/build-module/use-view.mjs.map +1 -7
- package/package.json +9 -9
- package/build/index.cjs.map +0 -7
- package/build/types.cjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/types.mjs.map +0 -7
package/build/index.cjs
CHANGED
|
@@ -1,37 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/views/src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
loadView: () => import_load_view.loadView,
|
|
24
|
-
useView: () => import_use_view.useView,
|
|
25
|
-
useViewConfig: () => import_use_view_config.useViewConfig
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
26
5
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
6
|
+
let __use_view_ts = require("./use-view.cjs");
|
|
7
|
+
let __load_view_ts = require("./load-view.cjs");
|
|
8
|
+
let __use_view_config_ts = require("./use-view-config.cjs");
|
|
9
|
+
Object.defineProperty(exports, "loadView", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return __load_view_ts.loadView;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "useView", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function() {
|
|
18
|
+
return __use_view_ts.useView;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "useViewConfig", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function() {
|
|
24
|
+
return __use_view_config_ts.useViewConfig;
|
|
25
|
+
}
|
|
36
26
|
});
|
|
37
|
-
//# sourceMappingURL=index.cjs.map
|
package/build/load-view.cjs
CHANGED
|
@@ -1,57 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/views/src/load-view.ts
|
|
21
|
-
var load_view_exports = {};
|
|
22
|
-
__export(load_view_exports, {
|
|
23
|
-
loadView: () => loadView
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
5
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
let _wordpress_data = require("@wordpress/data");
|
|
7
|
+
let _wordpress_preferences = require("@wordpress/preferences");
|
|
8
|
+
let __preference_keys_ts = require("./preference-keys.cjs");
|
|
9
|
+
let __resolve_view_ts = require("./resolve-view.cjs");
|
|
10
|
+
// packages/views/src/load-view.ts
|
|
11
|
+
/**
|
|
12
|
+
* Async function for loading view state in route loaders.
|
|
13
|
+
*
|
|
14
|
+
* Resolves the same layers `useView` does, so a route loader and the hook that
|
|
15
|
+
* takes over from it agree on the view.
|
|
16
|
+
*
|
|
17
|
+
* @param config Configuration object for loading the view.
|
|
18
|
+
* @param config.kind Entity kind (e.g., 'postType', 'taxonomy', 'root').
|
|
19
|
+
* @param config.name Specific entity name.
|
|
20
|
+
* @param config.slug View identifier.
|
|
21
|
+
* @param config.defaultView Default view configuration.
|
|
22
|
+
* @param config.defaultLayouts Default layout configurations keyed by layout type.
|
|
23
|
+
* @param config.activeViewOverrides View overrides applied on top but never persisted.
|
|
24
|
+
* @param config.queryParams Object with `page` and/or `search` from URL.
|
|
25
|
+
* @return Promise resolving to the loaded view object.
|
|
26
|
+
*/
|
|
30
27
|
async function loadView(config) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
import_preferences.store
|
|
43
|
-
).get("core/views", preferenceKey);
|
|
44
|
-
return (0, import_resolve_view.resolveView)({
|
|
45
|
-
defaultView,
|
|
46
|
-
defaultLayouts,
|
|
47
|
-
activeViewOverrides,
|
|
48
|
-
persistedView,
|
|
49
|
-
page: queryParams?.page,
|
|
50
|
-
search: queryParams?.search
|
|
51
|
-
});
|
|
28
|
+
const { kind, name, slug, defaultView, defaultLayouts, activeViewOverrides, queryParams } = config;
|
|
29
|
+
const preferenceKey = (0, __preference_keys_ts.generatePreferenceKey)(kind, name, slug);
|
|
30
|
+
const persistedView = (0, _wordpress_data.select)(_wordpress_preferences.store).get("core/views", preferenceKey);
|
|
31
|
+
return (0, __resolve_view_ts.resolveView)({
|
|
32
|
+
defaultView,
|
|
33
|
+
defaultLayouts,
|
|
34
|
+
activeViewOverrides,
|
|
35
|
+
persistedView,
|
|
36
|
+
page: queryParams?.page,
|
|
37
|
+
search: queryParams?.search
|
|
38
|
+
});
|
|
52
39
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
//# sourceMappingURL=load-view.cjs.map
|
|
40
|
+
exports.loadView = loadView;
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=load-view.cjs.map
|
package/build/load-view.cjs.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/load-view.ts"],
|
|
4
|
-
"sourcesContent": ["import { select } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { generatePreferenceKey } from './preference-keys';\nimport { resolveView } from './resolve-view';\nimport type { ViewConfig, ViewOverrides } from './types';\n\n/**\n * Async function for loading view state in route loaders.\n *\n * Resolves the same layers `useView` does, so a route loader and the hook that\n * takes over from it agree on the view.\n *\n * @param config Configuration object for loading the view.\n * @param config.kind Entity kind (e.g., 'postType', 'taxonomy', 'root').\n * @param config.name Specific entity name.\n * @param config.slug View identifier.\n * @param config.defaultView Default view configuration.\n * @param config.defaultLayouts Default layout configurations keyed by layout type.\n * @param config.activeViewOverrides View overrides applied on top but never persisted.\n * @param config.queryParams Object with `page` and/or `search` from URL.\n * @return Promise resolving to the loaded view object.\n */\nexport async function loadView( config: ViewConfig ) {\n\tconst {\n\t\tkind,\n\t\tname,\n\t\tslug,\n\t\tdefaultView,\n\t\tdefaultLayouts,\n\t\tactiveViewOverrides,\n\t\tqueryParams,\n\t} = config;\n\tconst preferenceKey = generatePreferenceKey( kind, name, slug );\n\tconst persistedView: ViewOverrides | undefined = select(\n\t\tpreferencesStore\n\t).get( 'core/views', preferenceKey ) as ViewOverrides | undefined;\n\n\treturn resolveView( {\n\t\tdefaultView,\n\t\tdefaultLayouts,\n\t\tactiveViewOverrides,\n\t\tpersistedView,\n\t\tpage: queryParams?.page,\n\t\tsearch: queryParams?.search,\n\t} );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAuB;AACvB,yBAA0C;AAC1C,6BAAsC;AACtC,0BAA4B;AAmB5B,eAAsB,SAAU,QAAqB;AACpD,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI;AACJ,QAAM,oBAAgB,8CAAuB,MAAM,MAAM,IAAK;AAC9D,QAAM,oBAA2C;AAAA,IAChD,mBAAAA;AAAA,EACD,EAAE,IAAK,cAAc,aAAc;AAEnC,aAAO,iCAAa;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,aAAa;AAAA,IACnB,QAAQ,aAAa;AAAA,EACtB,CAAE;AACH;",
|
|
6
|
-
"names": ["preferencesStore"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"load-view.cjs","names":["generatePreferenceKey","select","preferencesStore","resolveView"],"sources":["../src/load-view.ts"],"sourcesContent":["import { select } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { generatePreferenceKey } from './preference-keys';\nimport { resolveView } from './resolve-view';\nimport type { ViewConfig, ViewOverrides } from './types';\n\n/**\n * Async function for loading view state in route loaders.\n *\n * Resolves the same layers `useView` does, so a route loader and the hook that\n * takes over from it agree on the view.\n *\n * @param config Configuration object for loading the view.\n * @param config.kind Entity kind (e.g., 'postType', 'taxonomy', 'root').\n * @param config.name Specific entity name.\n * @param config.slug View identifier.\n * @param config.defaultView Default view configuration.\n * @param config.defaultLayouts Default layout configurations keyed by layout type.\n * @param config.activeViewOverrides View overrides applied on top but never persisted.\n * @param config.queryParams Object with `page` and/or `search` from URL.\n * @return Promise resolving to the loaded view object.\n */\nexport async function loadView( config: ViewConfig ) {\n\tconst {\n\t\tkind,\n\t\tname,\n\t\tslug,\n\t\tdefaultView,\n\t\tdefaultLayouts,\n\t\tactiveViewOverrides,\n\t\tqueryParams,\n\t} = config;\n\tconst preferenceKey = generatePreferenceKey( kind, name, slug );\n\tconst persistedView: ViewOverrides | undefined = select(\n\t\tpreferencesStore\n\t).get( 'core/views', preferenceKey ) as ViewOverrides | undefined;\n\n\treturn resolveView( {\n\t\tdefaultView,\n\t\tdefaultLayouts,\n\t\tactiveViewOverrides,\n\t\tpersistedView,\n\t\tpage: queryParams?.page,\n\t\tsearch: queryParams?.search,\n\t} );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,eAAsB,SAAU,QAAqB;CACpD,MAAM,EACL,MACA,MACA,MACA,aACA,gBACA,qBACA,gBACG;CACJ,MAAM,iBAAA,GAAgBA,qBAAAA,sBAAAA,CAAuB,MAAM,MAAM,IAAK;CAC9D,MAAM,iBAAA,GAA2CC,gBAAAA,OAAAA,CAChDC,uBAAAA,KACD,CAAC,CAAC,IAAK,cAAc,aAAc;CAEnC,QAAA,GAAOC,kBAAAA,YAAAA,CAAa;EACnB;EACA;EACA;EACA;EACA,MAAM,aAAa;EACnB,QAAQ,aAAa;CACtB,CAAE;AACH"}
|
package/build/lock-unlock.cjs
CHANGED
|
@@ -1,37 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/views/src/lock-unlock.ts
|
|
21
|
-
var lock_unlock_exports = {};
|
|
22
|
-
__export(lock_unlock_exports, {
|
|
23
|
-
lock: () => lock,
|
|
24
|
-
unlock: () => unlock
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(lock_unlock_exports);
|
|
27
|
-
var import_private_apis = require("@wordpress/private-apis");
|
|
28
|
-
var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
|
|
29
|
-
"I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
|
|
30
|
-
"@wordpress/views"
|
|
31
|
-
);
|
|
32
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
-
0 && (module.exports = {
|
|
34
|
-
lock,
|
|
35
|
-
unlock
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
36
5
|
});
|
|
37
|
-
|
|
6
|
+
// packages/views/src/lock-unlock.ts
|
|
7
|
+
const { lock, unlock } = (0, require("@wordpress/private-apis").__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.", "@wordpress/views");
|
|
8
|
+
exports.lock = lock;
|
|
9
|
+
exports.unlock = unlock;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=lock-unlock.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/lock-unlock.ts"],
|
|
4
|
-
"sourcesContent": ["import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/views'\n\t);\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAiE;AAE1D,IAAM,EAAE,MAAM,OAAO,QAC3B;AAAA,EACC;AAAA,EACA;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"lock-unlock.cjs","names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules"],"sources":["../src/lock-unlock.ts"],"sourcesContent":["import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/views'\n\t);\n"],"mappings":";;;;;;AAEA,MAAa,EAAE,MAAM,YAAA,G,iCACpBA,CAAAA,CAAAA,iDAAAA,CACC,iIACA,kBACD"}
|
|
@@ -1,33 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/views/src/preference-keys.ts
|
|
21
|
-
var preference_keys_exports = {};
|
|
22
|
-
__export(preference_keys_exports, {
|
|
23
|
-
generatePreferenceKey: () => generatePreferenceKey
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
5
|
});
|
|
25
|
-
|
|
6
|
+
// packages/views/src/preference-keys.ts
|
|
7
|
+
/**
|
|
8
|
+
* Generates a unique preference key for a DataViews view.
|
|
9
|
+
*
|
|
10
|
+
* @param kind The entity kind (e.g., 'postType', 'root')
|
|
11
|
+
* @param name The specific entity name (e.g., 'post', 'user', 'site')
|
|
12
|
+
* @param slug The specific entity slug (e.g., 'category', 'post', 'all')
|
|
13
|
+
* @return The preference key string
|
|
14
|
+
*/
|
|
26
15
|
function generatePreferenceKey(kind, name, slug) {
|
|
27
|
-
|
|
16
|
+
return `dataviews-${kind}-${name}-${slug}`;
|
|
28
17
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
//# sourceMappingURL=preference-keys.cjs.map
|
|
18
|
+
exports.generatePreferenceKey = generatePreferenceKey;
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=preference-keys.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/preference-keys.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Generates a unique preference key for a DataViews view.\n *\n * @param kind The entity kind (e.g., 'postType', 'root')\n * @param name The specific entity name (e.g., 'post', 'user', 'site')\n * @param slug The specific entity slug (e.g., 'category', 'post', 'all')\n * @return The preference key string\n */\nexport function generatePreferenceKey(\n\tkind: string,\n\tname: string,\n\tslug: string\n): string {\n\treturn `dataviews-${ kind }-${ name }-${ slug }`;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,sBACf,MACA,MACA,MACS;AACT,SAAO,aAAc,IAAK,IAAK,IAAK,IAAK,IAAK;AAC/C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"preference-keys.cjs","names":[],"sources":["../src/preference-keys.ts"],"sourcesContent":["/**\n * Generates a unique preference key for a DataViews view.\n *\n * @param kind The entity kind (e.g., 'postType', 'root')\n * @param name The specific entity name (e.g., 'post', 'user', 'site')\n * @param slug The specific entity slug (e.g., 'category', 'post', 'all')\n * @return The preference key string\n */\nexport function generatePreferenceKey(\n\tkind: string,\n\tname: string,\n\tslug: string\n): string {\n\treturn `dataviews-${ kind }-${ name }-${ slug }`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAQA,SAAgB,sBACf,MACA,MACA,MACS;CACT,OAAO,aAAc,KAAM,GAAI,KAAM,GAAI;AAC1C"}
|
package/build/resolve-view.cjs
CHANGED
|
@@ -1,150 +1,199 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/views/src/resolve-view.ts
|
|
21
|
-
var resolve_view_exports = {};
|
|
22
|
-
__export(resolve_view_exports, {
|
|
23
|
-
getApplicablePersistedView: () => getApplicablePersistedView,
|
|
24
|
-
getUserModifications: () => getUserModifications,
|
|
25
|
-
resolveView: () => resolveView
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
26
5
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
let dequal = require("dequal");
|
|
7
|
+
// packages/views/src/resolve-view.ts
|
|
8
|
+
/**
|
|
9
|
+
* `page` and `search` are URL-managed: the URL is their only source. They are
|
|
10
|
+
* never persisted, and no other layer may configure them — an absent URL param
|
|
11
|
+
* is indistinguishable from the user having cleared the value, so any fallback
|
|
12
|
+
* would resurrect a cleared search on the next read.
|
|
13
|
+
*/
|
|
14
|
+
const QUERY_PARAMS = ["page", "search"];
|
|
30
15
|
function isPlainObject(value) {
|
|
31
|
-
|
|
16
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Copies a layer without the URL-managed properties.
|
|
20
|
+
*
|
|
21
|
+
* @param layer The layer to copy.
|
|
22
|
+
* @return A copy of the layer with `page` and `search` removed.
|
|
23
|
+
*/
|
|
33
24
|
function withoutQueryParams(layer) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
25
|
+
const result = isPlainObject(layer) ? { ...layer } : {};
|
|
26
|
+
for (const key of QUERY_PARAMS) delete result[key];
|
|
27
|
+
return result;
|
|
39
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Merges a layer on top of another, recursing into plain objects so the upper
|
|
31
|
+
* layer only takes over the leaves it declares. Arrays and scalars are leaves:
|
|
32
|
+
* they are replaced wholesale.
|
|
33
|
+
*
|
|
34
|
+
* Nested properties (`layout.styles.<field>.width`, `groupBy.direction`,
|
|
35
|
+
* `sort.direction`) are merged leaf by leaf: a shallow merge would let a layer
|
|
36
|
+
* that only declares one leaf wipe every sibling the layers below provide.
|
|
37
|
+
*
|
|
38
|
+
* @param lower The layer to merge into.
|
|
39
|
+
* @param upper The layer to merge on top.
|
|
40
|
+
* @return The merged layer.
|
|
41
|
+
*/
|
|
40
42
|
function mergeLayer(lower, upper) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
const result = { ...lower };
|
|
44
|
+
for (const key of Object.keys(upper)) {
|
|
45
|
+
const value = upper[key];
|
|
46
|
+
const current = result[key];
|
|
47
|
+
result[key] = isPlainObject(current) && isPlainObject(value) ? mergeLayer(current, value) : value;
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
48
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The leaves of `value` that differ from `base`. Mirrors `mergeLayer`:
|
|
53
|
+
* `mergeLayer( base, diffLayer( value, base ) )` resolves back to `value`.
|
|
54
|
+
*
|
|
55
|
+
* A persisted leaf that equals both `value` and `base` is kept even though it
|
|
56
|
+
* is not a difference: the preference is shared by every view of the same
|
|
57
|
+
* entity, and such a leaf may only differ from the base of *another* view. In
|
|
58
|
+
* this one, where it coincides with the base, a revert is unobservable — so
|
|
59
|
+
* equality cannot mean the user reverted it. Dropping a persisted leaf
|
|
60
|
+
* requires `value` to actually move away from it, back to `base`.
|
|
61
|
+
*
|
|
62
|
+
* @param value The layer to compare.
|
|
63
|
+
* @param base The layer to compare it against.
|
|
64
|
+
* @param persisted The previously persisted leaves.
|
|
65
|
+
* @return The leaves that differ, as a layer of its own.
|
|
66
|
+
*/
|
|
49
67
|
function diffLayer(value, base, persisted = {}) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
64
|
-
if (Object.keys(nested).length > 0) {
|
|
65
|
-
result[key] = nested;
|
|
66
|
-
}
|
|
67
|
-
} else if (!(0, import_dequal.dequal)(next, current)) {
|
|
68
|
-
result[key] = next;
|
|
69
|
-
} else if (prev !== void 0 && (0, import_dequal.dequal)(next, prev)) {
|
|
70
|
-
result[key] = prev;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
68
|
+
const result = {};
|
|
69
|
+
for (const key of Object.keys(value)) {
|
|
70
|
+
const next = value[key];
|
|
71
|
+
const current = base[key];
|
|
72
|
+
const prev = persisted[key];
|
|
73
|
+
if (next === void 0) continue;
|
|
74
|
+
if (isPlainObject(next) && isPlainObject(current)) {
|
|
75
|
+
const nested = diffLayer(next, current, isPlainObject(prev) ? prev : {});
|
|
76
|
+
if (Object.keys(nested).length > 0) result[key] = nested;
|
|
77
|
+
} else if (!(0, dequal.dequal)(next, current)) result[key] = next;
|
|
78
|
+
else if (prev !== void 0 && (0, dequal.dequal)(next, prev)) result[key] = prev;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
74
81
|
}
|
|
75
82
|
function getLockedFilters(overrides) {
|
|
76
|
-
|
|
83
|
+
return (overrides?.filters ?? []).filter((filter) => filter.isLocked);
|
|
77
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Hoists the locked filters an override provides to the front of the view's
|
|
87
|
+
* filters, replacing any same-field filter. Locked filters are not the user's
|
|
88
|
+
* to change, so they are pinned in place instead of taking part in the layer
|
|
89
|
+
* resolution.
|
|
90
|
+
*
|
|
91
|
+
* @param view The view to apply the locked filters to.
|
|
92
|
+
* @param overrides The active view overrides.
|
|
93
|
+
* @return The view with the locked filters applied.
|
|
94
|
+
*/
|
|
78
95
|
function applyLockedFilters(view, overrides) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return { ...view, filters: [...locked, ...rest] };
|
|
96
|
+
const locked = getLockedFilters(overrides);
|
|
97
|
+
if (locked.length === 0) return view;
|
|
98
|
+
const rest = (view.filters ?? []).filter((filter) => !locked.some((f) => f.field === filter.field));
|
|
99
|
+
return {
|
|
100
|
+
...view,
|
|
101
|
+
filters: [...locked, ...rest]
|
|
102
|
+
};
|
|
87
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* The user's persisted modifications that still apply.
|
|
106
|
+
*
|
|
107
|
+
* A persisted `type` that `defaultLayouts` does not offer is dropped: DataViews
|
|
108
|
+
* renders nothing for a layout it is not given, and the preference may predate
|
|
109
|
+
* the current set of layouts (a screen that used to offer the list layout, say,
|
|
110
|
+
* and no longer does). The type then resolves out of the layers below, and the
|
|
111
|
+
* other modifications are kept. Without `defaultLayouts` every type is offered.
|
|
112
|
+
*
|
|
113
|
+
* `true` is a valid entry, so the check mirrors DataViews': an entry counts as
|
|
114
|
+
* long as it is truthy.
|
|
115
|
+
*
|
|
116
|
+
* @param persistedView The user's persisted modifications.
|
|
117
|
+
* @param defaultLayouts The layouts on offer, keyed by layout type.
|
|
118
|
+
* @return The modifications that apply, or `undefined` when there are none.
|
|
119
|
+
*/
|
|
88
120
|
function getApplicablePersistedView(persistedView, defaultLayouts) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const { type, ...rest } = persistedView;
|
|
93
|
-
return Object.keys(rest).length > 0 ? rest : void 0;
|
|
121
|
+
if (!persistedView || persistedView.type === void 0 || !defaultLayouts || defaultLayouts[persistedView.type]) return persistedView;
|
|
122
|
+
const { type, ...rest } = persistedView;
|
|
123
|
+
return Object.keys(rest).length > 0 ? rest : void 0;
|
|
94
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Resolves the layers below the user's modifications — what a modification has
|
|
127
|
+
* to differ from to count as one. The layout type selects which entry of
|
|
128
|
+
* `defaultLayouts` applies, so the base only makes sense relative to a type.
|
|
129
|
+
*
|
|
130
|
+
* @param layers The layers to resolve.
|
|
131
|
+
* @param effectiveType The layout type to resolve the base at.
|
|
132
|
+
* @return The resolved base view.
|
|
133
|
+
*/
|
|
95
134
|
function resolveBaseView(layers, effectiveType) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
[layoutDefaults, activeViewOverrides].reduce(
|
|
100
|
-
(lower, upper) => mergeLayer(lower, withoutQueryParams(upper)),
|
|
101
|
-
withoutQueryParams(defaultView)
|
|
102
|
-
),
|
|
103
|
-
activeViewOverrides
|
|
104
|
-
);
|
|
135
|
+
const { defaultView, defaultLayouts, activeViewOverrides } = layers;
|
|
136
|
+
const layoutDefaults = defaultLayouts?.[effectiveType];
|
|
137
|
+
return applyLockedFilters([layoutDefaults, activeViewOverrides].reduce((lower, upper) => mergeLayer(lower, withoutQueryParams(upper)), withoutQueryParams(defaultView)), activeViewOverrides);
|
|
105
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Resolves a view out of its layers. Later layers override earlier ones:
|
|
141
|
+
*
|
|
142
|
+
* 1. `defaultView`
|
|
143
|
+
* 2. `defaultLayouts` (for the effective type)
|
|
144
|
+
* 3. `activeViewOverrides`
|
|
145
|
+
* 4. the user's persisted modifications (see `getApplicablePersistedView`)
|
|
146
|
+
* 5. the URL query params (`page` and `search` only)
|
|
147
|
+
*
|
|
148
|
+
* @param args See `ResolveViewArgs`.
|
|
149
|
+
* @return The resolved `view`.
|
|
150
|
+
*/
|
|
106
151
|
function resolveView(args) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const view = {
|
|
115
|
-
...applyLockedFilters(
|
|
116
|
-
mergeLayer(baseView, withoutQueryParams(persistedView)),
|
|
117
|
-
activeViewOverrides
|
|
118
|
-
),
|
|
119
|
-
page: Number(page ?? 1),
|
|
120
|
-
search: search ?? ""
|
|
121
|
-
};
|
|
122
|
-
return view;
|
|
152
|
+
const { defaultView, defaultLayouts, activeViewOverrides, page, search } = args;
|
|
153
|
+
const persistedView = getApplicablePersistedView(args.persistedView, defaultLayouts);
|
|
154
|
+
return {
|
|
155
|
+
...applyLockedFilters(mergeLayer(resolveBaseView(args, persistedView?.type ?? activeViewOverrides?.type ?? defaultView?.type), withoutQueryParams(persistedView)), activeViewOverrides),
|
|
156
|
+
page: Number(page ?? 1),
|
|
157
|
+
search: search ?? ""
|
|
158
|
+
};
|
|
123
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* The user's modifications: the leaves of the view they interacted with that
|
|
162
|
+
* the layers below do not already resolve to. This is what gets persisted, so
|
|
163
|
+
* that a change to any of those layers keeps showing through the properties the
|
|
164
|
+
* user never touched.
|
|
165
|
+
*
|
|
166
|
+
* Previously persisted leaves that coincide with the base of the current view
|
|
167
|
+
* are carried over rather than dropped: they may still make a difference in
|
|
168
|
+
* another view sharing the preference. See `diffLayer`.
|
|
169
|
+
*
|
|
170
|
+
* The diff basis is resolved at `newView.type`, not at the type the previous
|
|
171
|
+
* resolution used: the type selects the `defaultLayouts` entry, and a layout
|
|
172
|
+
* switch reports the new type together with that entry's values. Diffing them
|
|
173
|
+
* against the previous type's base would persist the difference between the
|
|
174
|
+
* two entries as if the user had picked those values — leaves the layouts
|
|
175
|
+
* already provide, which then linger as phantom modifications after switching
|
|
176
|
+
* back.
|
|
177
|
+
*
|
|
178
|
+
* A persisted `type` the current layouts do not offer never applied (see
|
|
179
|
+
* `getApplicablePersistedView`), so it is not carried over either: the
|
|
180
|
+
* modifications returned replace it with whatever the user picked.
|
|
181
|
+
*
|
|
182
|
+
* @param newView The view the user produced.
|
|
183
|
+
* @param layers The layers the view resolves from. See `ViewLayers`.
|
|
184
|
+
* @return The modified properties, or `undefined` when the user modified none.
|
|
185
|
+
*/
|
|
124
186
|
function getUserModifications(newView, layers) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
withoutQueryParams(newView),
|
|
133
|
-
withoutQueryParams(baseView),
|
|
134
|
-
withoutQueryParams(persistedView)
|
|
135
|
-
);
|
|
136
|
-
const locked = getLockedFilters(activeViewOverrides);
|
|
137
|
-
if (locked.length > 0 && Array.isArray(modifications.filters)) {
|
|
138
|
-
modifications.filters = modifications.filters.filter(
|
|
139
|
-
(filter) => !locked.some((f) => f.field === filter.field)
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
return Object.keys(modifications).length > 0 ? modifications : void 0;
|
|
187
|
+
const { defaultLayouts, activeViewOverrides } = layers;
|
|
188
|
+
const persistedView = getApplicablePersistedView(layers.persistedView, defaultLayouts);
|
|
189
|
+
const baseView = resolveBaseView(layers, newView.type);
|
|
190
|
+
const modifications = diffLayer(withoutQueryParams(newView), withoutQueryParams(baseView), withoutQueryParams(persistedView));
|
|
191
|
+
const locked = getLockedFilters(activeViewOverrides);
|
|
192
|
+
if (locked.length > 0 && Array.isArray(modifications.filters)) modifications.filters = modifications.filters.filter((filter) => !locked.some((f) => f.field === filter.field));
|
|
193
|
+
return Object.keys(modifications).length > 0 ? modifications : void 0;
|
|
143
194
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
});
|
|
150
|
-
//# sourceMappingURL=resolve-view.cjs.map
|
|
195
|
+
exports.getApplicablePersistedView = getApplicablePersistedView;
|
|
196
|
+
exports.getUserModifications = getUserModifications;
|
|
197
|
+
exports.resolveView = resolveView;
|
|
198
|
+
|
|
199
|
+
//# sourceMappingURL=resolve-view.cjs.map
|