@wix/site-service-pages 1.8.0 → 1.10.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/README.md CHANGED
@@ -17,16 +17,20 @@ import { PagesService } from '@wix/site-service-pages/implementations'
17
17
  createServicesMap().addService(PagesDefinition, PagesService, config)
18
18
 
19
19
  const service = servicesManager.getService(PagesDefinition)
20
- // service.pages ← Record<string, Page>
20
+ // service.pages ← Record<string, PageConfig>, keyed by page ID
21
21
  // service.mainPage ← Page (resolved by provider, stored as-is)
22
22
  // service.currentPage ← Page (resolved by provider, stored as-is)
23
+
24
+ // Find a page by its slug:
25
+ const springPage = Object.values(service.pages).find((page) => page.slug === 'spring')
26
+ const onMainPage = service.currentPage.slug === service.mainPage.slug
23
27
  ```
24
28
 
25
29
  ## API
26
30
 
27
31
  | Member | Type | Throws when | Description |
28
32
  |---|---|---|---|
29
- | `pages` | `Record<string, Page>` | never | All pages with `id` stamped from map key. |
33
+ | `pages` | `Record<string, PageConfig>` | never | All pages, keyed by page ID. Each page also has its `slug`. |
30
34
  | `mainPage` | `Page` | never | The site's main/home page as provided. |
31
35
  | `currentPage` | `Page` | never | The currently active page as provided. |
32
36
  | `_updateConfig` | `(Partial<IPagesServiceConfig>) => void` | never | Replace-on-write per field. Re-stamps `id` on `pages` update. |
@@ -37,7 +41,7 @@ const service = servicesManager.getService(PagesDefinition)
37
41
 
38
42
  ```ts
39
43
  type IPagesServiceConfig = {
40
- /** id-as-key map; values omit `id` (P3). Service stamps id at write time (P16). */
44
+ /** id-as-key map; values omit `id` (P3) and carry `slug`. */
41
45
  pages: Record<string, PageConfig>
42
46
  /** Provider resolves and passes the full main page object. */
43
47
  mainPage: Page
@@ -47,7 +51,11 @@ type IPagesServiceConfig = {
47
51
 
48
52
  type PageConfig = {
49
53
  title: string
54
+ /** The page's `pageUriSEO`, unique across the site, including popups. */
55
+ slug: string
50
56
  path: string
57
+ /** Slug of the parent page. */
58
+ parentSlug?: string
51
59
  parentPageId?: string
52
60
  popup: boolean
53
61
  /** TPA page identifier (e.g. `ecom_side_cart`). Not globally unique on its own — pair with `appDefinitionId`. */
@@ -61,6 +69,8 @@ type Page = PageConfig & { id: string }
61
69
 
62
70
  The provider is responsible for resolving which page is `mainPage` / `currentPage` before injecting config. The service stores them as independent signals and does no internal lookup.
63
71
 
72
+ The provider supplies `slug` on every page, and `parentSlug` alongside `parentPageId`.
73
+
64
74
  ## Reactivity
65
75
 
66
76
  This service is a thin signal wrapper over `@wix/services-definitions/core-services/signals`. All three properties are signal-backed; wrap reads in `effect` / `computed` to react to changes. Signals are not exposed directly.
@@ -11,18 +11,36 @@ export type PageConfig = {
11
11
  * @exampleValue 'Spring Collection'
12
12
  */
13
13
  title: string;
14
+ /**
15
+ * Page slug, the page's own segment of its URL, as a Wix user set it in the page's SEO settings.
16
+ *
17
+ * The slug is unique across the site, including popups, so use it to find a page in the `pages` map or
18
+ * to compare two pages. A Wix user can change it, and a multilingual site can translate it, so don't
19
+ * store it. To identify an app's page across sites, use `appPageId` and `appDefinitionId`.
20
+ *
21
+ * @exampleValue 'spring'
22
+ */
23
+ slug: string;
14
24
  /**
15
25
  * Page path, relative to the site root URL.
16
26
  *
17
27
  * For a nested page, the path usually starts with its parent page's path, such as `collections/spring`.
18
28
  * When a Wix user turns off URL hierarchy in the site's SEO settings, the path is just the page's own
19
- * slug, such as `spring`. To find a page's parent, use `parentPageId`, not the path.
29
+ * slug, such as `spring`. To find a page's parent, use `parentSlug`, not the path.
20
30
  *
21
31
  * To build the page's URL, join the site root URL and the path with a single `/`.
22
32
  *
23
33
  * @exampleValue 'collections/spring'
24
34
  */
25
35
  path: string;
36
+ /**
37
+ * Slug of this page's parent page in the site's page structure.
38
+ *
39
+ * Undefined if the page doesn't have a parent page.
40
+ *
41
+ * @exampleValue 'collections'
42
+ */
43
+ parentSlug?: string;
26
44
  /**
27
45
  * ID of this page's parent page in the site's page structure.
28
46
  *
@@ -43,14 +61,21 @@ export type PageConfig = {
43
61
  * App page ID of this page.
44
62
  *
45
63
  * The ID stays the same across sites, even though a Wix user can change the page's path. It's unique
46
- * only within its app, so another installed app can use the same ID.
64
+ * only within its app, so another installed app can use the same ID. To identify an app's page, check
65
+ * `appDefinitionId` too.
47
66
  *
48
67
  * Available only for a page that belongs to an installed app.
49
68
  *
50
69
  * @exampleValue 'ecom_side_cart'
51
70
  */
52
71
  appPageId?: string;
53
- /** @internal Not documented: the host doesn't populate it yet (host PR #48632 set only `appPageId`). */
72
+ /**
73
+ * ID of the app that this page belongs to. This is the app's `appDefinitionId`.
74
+ *
75
+ * Available only for a page that belongs to an installed app.
76
+ *
77
+ * @exampleValue '1380b703-ce81-ff05-f115-39571d94dfcd'
78
+ */
54
79
  appDefinitionId?: string;
55
80
  };
56
81
  /** A page on a site, including its ID. */
@@ -64,7 +89,7 @@ export type Page = PageConfig & {
64
89
  };
65
90
  /** Values the host supplies when it creates the service. */
66
91
  export type IPagesServiceConfig = {
67
- /** Every page on the site, keyed by page ID. The values have no `id`. */
92
+ /** Every page on the site, keyed by page ID. The values have no `id`, and each has its `slug`. */
68
93
  pages: {
69
94
  [pageId: string]: PageConfig;
70
95
  };
@@ -81,12 +106,13 @@ export interface IPagesService {
81
106
  /**
82
107
  * Every page on the site, keyed by page ID.
83
108
  *
84
- * The values don't include an `id`. Use the key as the page's ID.
109
+ * The values don't include an `id`. Use the key as the page's ID. To find a page by its slug, search the
110
+ * values: `Object.values(pages).find((page) => page.slug === slug)`.
85
111
  *
86
112
  * Don't change the map or its pages. Every component on the page reads the same map, so a change shows in
87
113
  * all of them, and the site doesn't save it.
88
114
  *
89
- * @exampleValue `{ "m4rw8": { "title": "Home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "path": "collections/spring", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart" } }`
115
+ * @exampleValue `{ "m4rw8": { "title": "Home", "slug": "home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "slug": "shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "slug": "collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "slug": "spring", "path": "collections/spring", "parentSlug": "collections", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "slug": "side-cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart", "appDefinitionId": "1380b703-ce81-ff05-f115-39571d94dfcd" } }`
90
116
  */
91
117
  readonly pages: {
92
118
  [pageId: string]: PageConfig;
@@ -95,12 +121,12 @@ export interface IPagesService {
95
121
  * Main page, the page a site visitor reaches at the site root URL.
96
122
  *
97
123
  * A Wix user chooses which page this is. To check whether the page that's currently displayed is the
98
- * main page, compare `currentPage.id` with `mainPage.id`.
124
+ * main page, compare `currentPage.slug` with `mainPage.slug`.
99
125
  *
100
126
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
101
127
  * them, and the site doesn't save it.
102
128
  *
103
- * @exampleValue `{ "id": "m4rw8", "title": "Home", "path": "home", "popup": false }`
129
+ * @exampleValue `{ "id": "m4rw8", "title": "Home", "slug": "home", "path": "home", "popup": false }`
104
130
  */
105
131
  readonly mainPage: Page;
106
132
  /**
@@ -109,7 +135,7 @@ export interface IPagesService {
109
135
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
110
136
  * them, and the site doesn't save it.
111
137
  *
112
- * @exampleValue `{ "id": "c1dmp", "title": "Shop", "path": "shop", "popup": false }`
138
+ * @exampleValue `{ "id": "c1dmp", "title": "Shop", "slug": "shop", "path": "shop", "popup": false }`
113
139
  */
114
140
  readonly currentPage: Page;
115
141
  /** @internal Host-only. Replaces config values when the host's state changes. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;AA4H5C,QAAA,eAAe,GAAG,IAAA,oCAAa,EAAqC,yBAAyB,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/definition/index.ts"],"names":[],"mappings":";;;AAAA,oEAAyD;AAsJ5C,QAAA,eAAe,GAAG,IAAA,oCAAa,EAAqC,yBAAyB,CAAC,CAAA"}
@@ -11,18 +11,36 @@ export type PageConfig = {
11
11
  * @exampleValue 'Spring Collection'
12
12
  */
13
13
  title: string;
14
+ /**
15
+ * Page slug, the page's own segment of its URL, as a Wix user set it in the page's SEO settings.
16
+ *
17
+ * The slug is unique across the site, including popups, so use it to find a page in the `pages` map or
18
+ * to compare two pages. A Wix user can change it, and a multilingual site can translate it, so don't
19
+ * store it. To identify an app's page across sites, use `appPageId` and `appDefinitionId`.
20
+ *
21
+ * @exampleValue 'spring'
22
+ */
23
+ slug: string;
14
24
  /**
15
25
  * Page path, relative to the site root URL.
16
26
  *
17
27
  * For a nested page, the path usually starts with its parent page's path, such as `collections/spring`.
18
28
  * When a Wix user turns off URL hierarchy in the site's SEO settings, the path is just the page's own
19
- * slug, such as `spring`. To find a page's parent, use `parentPageId`, not the path.
29
+ * slug, such as `spring`. To find a page's parent, use `parentSlug`, not the path.
20
30
  *
21
31
  * To build the page's URL, join the site root URL and the path with a single `/`.
22
32
  *
23
33
  * @exampleValue 'collections/spring'
24
34
  */
25
35
  path: string;
36
+ /**
37
+ * Slug of this page's parent page in the site's page structure.
38
+ *
39
+ * Undefined if the page doesn't have a parent page.
40
+ *
41
+ * @exampleValue 'collections'
42
+ */
43
+ parentSlug?: string;
26
44
  /**
27
45
  * ID of this page's parent page in the site's page structure.
28
46
  *
@@ -43,14 +61,21 @@ export type PageConfig = {
43
61
  * App page ID of this page.
44
62
  *
45
63
  * The ID stays the same across sites, even though a Wix user can change the page's path. It's unique
46
- * only within its app, so another installed app can use the same ID.
64
+ * only within its app, so another installed app can use the same ID. To identify an app's page, check
65
+ * `appDefinitionId` too.
47
66
  *
48
67
  * Available only for a page that belongs to an installed app.
49
68
  *
50
69
  * @exampleValue 'ecom_side_cart'
51
70
  */
52
71
  appPageId?: string;
53
- /** @internal Not documented: the host doesn't populate it yet (host PR #48632 set only `appPageId`). */
72
+ /**
73
+ * ID of the app that this page belongs to. This is the app's `appDefinitionId`.
74
+ *
75
+ * Available only for a page that belongs to an installed app.
76
+ *
77
+ * @exampleValue '1380b703-ce81-ff05-f115-39571d94dfcd'
78
+ */
54
79
  appDefinitionId?: string;
55
80
  };
56
81
  /** A page on a site, including its ID. */
@@ -64,7 +89,7 @@ export type Page = PageConfig & {
64
89
  };
65
90
  /** Values the host supplies when it creates the service. */
66
91
  export type IPagesServiceConfig = {
67
- /** Every page on the site, keyed by page ID. The values have no `id`. */
92
+ /** Every page on the site, keyed by page ID. The values have no `id`, and each has its `slug`. */
68
93
  pages: {
69
94
  [pageId: string]: PageConfig;
70
95
  };
@@ -81,12 +106,13 @@ export interface IPagesService {
81
106
  /**
82
107
  * Every page on the site, keyed by page ID.
83
108
  *
84
- * The values don't include an `id`. Use the key as the page's ID.
109
+ * The values don't include an `id`. Use the key as the page's ID. To find a page by its slug, search the
110
+ * values: `Object.values(pages).find((page) => page.slug === slug)`.
85
111
  *
86
112
  * Don't change the map or its pages. Every component on the page reads the same map, so a change shows in
87
113
  * all of them, and the site doesn't save it.
88
114
  *
89
- * @exampleValue `{ "m4rw8": { "title": "Home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "path": "collections/spring", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart" } }`
115
+ * @exampleValue `{ "m4rw8": { "title": "Home", "slug": "home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "slug": "shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "slug": "collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "slug": "spring", "path": "collections/spring", "parentSlug": "collections", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "slug": "side-cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart", "appDefinitionId": "1380b703-ce81-ff05-f115-39571d94dfcd" } }`
90
116
  */
91
117
  readonly pages: {
92
118
  [pageId: string]: PageConfig;
@@ -95,12 +121,12 @@ export interface IPagesService {
95
121
  * Main page, the page a site visitor reaches at the site root URL.
96
122
  *
97
123
  * A Wix user chooses which page this is. To check whether the page that's currently displayed is the
98
- * main page, compare `currentPage.id` with `mainPage.id`.
124
+ * main page, compare `currentPage.slug` with `mainPage.slug`.
99
125
  *
100
126
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
101
127
  * them, and the site doesn't save it.
102
128
  *
103
- * @exampleValue `{ "id": "m4rw8", "title": "Home", "path": "home", "popup": false }`
129
+ * @exampleValue `{ "id": "m4rw8", "title": "Home", "slug": "home", "path": "home", "popup": false }`
104
130
  */
105
131
  readonly mainPage: Page;
106
132
  /**
@@ -109,7 +135,7 @@ export interface IPagesService {
109
135
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
110
136
  * them, and the site doesn't save it.
111
137
  *
112
- * @exampleValue `{ "id": "c1dmp", "title": "Shop", "path": "shop", "popup": false }`
138
+ * @exampleValue `{ "id": "c1dmp", "title": "Shop", "slug": "shop", "path": "shop", "popup": false }`
113
139
  */
114
140
  readonly currentPage: Page;
115
141
  /** @internal Host-only. Replaces config values when the host's state changes. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AA4HzD,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAqC,yBAAyB,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAsJzD,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAqC,yBAAyB,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/site-service-pages",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "license": "UNLICENSED",
5
5
  "files": [
6
6
  "dist",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  }
79
79
  },
80
- "falconPackageHash": "47c5a308a9f2b3c14c84bb656f850ad2fdce5a5d4954ae26485d26fb"
80
+ "falconPackageHash": "d568b273bf9a7f463a24f3c9e0c60003b8cffa648be73d8aca1a2505"
81
81
  }
@@ -13,18 +13,36 @@ export type PageConfig = {
13
13
  * @exampleValue 'Spring Collection'
14
14
  */
15
15
  title: string
16
+ /**
17
+ * Page slug, the page's own segment of its URL, as a Wix user set it in the page's SEO settings.
18
+ *
19
+ * The slug is unique across the site, including popups, so use it to find a page in the `pages` map or
20
+ * to compare two pages. A Wix user can change it, and a multilingual site can translate it, so don't
21
+ * store it. To identify an app's page across sites, use `appPageId` and `appDefinitionId`.
22
+ *
23
+ * @exampleValue 'spring'
24
+ */
25
+ slug: string
16
26
  /**
17
27
  * Page path, relative to the site root URL.
18
28
  *
19
29
  * For a nested page, the path usually starts with its parent page's path, such as `collections/spring`.
20
30
  * When a Wix user turns off URL hierarchy in the site's SEO settings, the path is just the page's own
21
- * slug, such as `spring`. To find a page's parent, use `parentPageId`, not the path.
31
+ * slug, such as `spring`. To find a page's parent, use `parentSlug`, not the path.
22
32
  *
23
33
  * To build the page's URL, join the site root URL and the path with a single `/`.
24
34
  *
25
35
  * @exampleValue 'collections/spring'
26
36
  */
27
37
  path: string
38
+ /**
39
+ * Slug of this page's parent page in the site's page structure.
40
+ *
41
+ * Undefined if the page doesn't have a parent page.
42
+ *
43
+ * @exampleValue 'collections'
44
+ */
45
+ parentSlug?: string
28
46
  /**
29
47
  * ID of this page's parent page in the site's page structure.
30
48
  *
@@ -45,14 +63,21 @@ export type PageConfig = {
45
63
  * App page ID of this page.
46
64
  *
47
65
  * The ID stays the same across sites, even though a Wix user can change the page's path. It's unique
48
- * only within its app, so another installed app can use the same ID.
66
+ * only within its app, so another installed app can use the same ID. To identify an app's page, check
67
+ * `appDefinitionId` too.
49
68
  *
50
69
  * Available only for a page that belongs to an installed app.
51
70
  *
52
71
  * @exampleValue 'ecom_side_cart'
53
72
  */
54
73
  appPageId?: string
55
- /** @internal Not documented: the host doesn't populate it yet (host PR #48632 set only `appPageId`). */
74
+ /**
75
+ * ID of the app that this page belongs to. This is the app's `appDefinitionId`.
76
+ *
77
+ * Available only for a page that belongs to an installed app.
78
+ *
79
+ * @exampleValue '1380b703-ce81-ff05-f115-39571d94dfcd'
80
+ */
56
81
  appDefinitionId?: string
57
82
  }
58
83
 
@@ -68,7 +93,7 @@ export type Page = PageConfig & {
68
93
 
69
94
  /** Values the host supplies when it creates the service. */
70
95
  export type IPagesServiceConfig = {
71
- /** Every page on the site, keyed by page ID. The values have no `id`. */
96
+ /** Every page on the site, keyed by page ID. The values have no `id`, and each has its `slug`. */
72
97
  pages: { [pageId: string]: PageConfig }
73
98
  /** The main page. The service stores it unchanged. */
74
99
  mainPage: Page
@@ -84,12 +109,13 @@ export interface IPagesService {
84
109
  /**
85
110
  * Every page on the site, keyed by page ID.
86
111
  *
87
- * The values don't include an `id`. Use the key as the page's ID.
112
+ * The values don't include an `id`. Use the key as the page's ID. To find a page by its slug, search the
113
+ * values: `Object.values(pages).find((page) => page.slug === slug)`.
88
114
  *
89
115
  * Don't change the map or its pages. Every component on the page reads the same map, so a change shows in
90
116
  * all of them, and the site doesn't save it.
91
117
  *
92
- * @exampleValue `{ "m4rw8": { "title": "Home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "path": "collections/spring", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart" } }`
118
+ * @exampleValue `{ "m4rw8": { "title": "Home", "slug": "home", "path": "home", "popup": false }, "c1dmp": { "title": "Shop", "slug": "shop", "path": "shop", "popup": false }, "i9xk2": { "title": "Collections", "slug": "collections", "path": "collections", "popup": false }, "t5nb6": { "title": "Spring Collection", "slug": "spring", "path": "collections/spring", "parentSlug": "collections", "parentPageId": "i9xk2", "popup": false }, "q7hz3": { "title": "Side Cart", "slug": "side-cart", "path": "side-cart", "popup": true, "appPageId": "ecom_side_cart", "appDefinitionId": "1380b703-ce81-ff05-f115-39571d94dfcd" } }`
93
119
  */
94
120
  readonly pages: { [pageId: string]: PageConfig }
95
121
 
@@ -97,12 +123,12 @@ export interface IPagesService {
97
123
  * Main page, the page a site visitor reaches at the site root URL.
98
124
  *
99
125
  * A Wix user chooses which page this is. To check whether the page that's currently displayed is the
100
- * main page, compare `currentPage.id` with `mainPage.id`.
126
+ * main page, compare `currentPage.slug` with `mainPage.slug`.
101
127
  *
102
128
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
103
129
  * them, and the site doesn't save it.
104
130
  *
105
- * @exampleValue `{ "id": "m4rw8", "title": "Home", "path": "home", "popup": false }`
131
+ * @exampleValue `{ "id": "m4rw8", "title": "Home", "slug": "home", "path": "home", "popup": false }`
106
132
  */
107
133
  readonly mainPage: Page
108
134
 
@@ -112,7 +138,7 @@ export interface IPagesService {
112
138
  * Don't change its fields. Every component on the page reads the same object, so a change shows in all of
113
139
  * them, and the site doesn't save it.
114
140
  *
115
- * @exampleValue `{ "id": "c1dmp", "title": "Shop", "path": "shop", "popup": false }`
141
+ * @exampleValue `{ "id": "c1dmp", "title": "Shop", "slug": "shop", "path": "shop", "popup": false }`
116
142
  */
117
143
  readonly currentPage: Page
118
144