@livepreso/cdk 0.0.1

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.
Files changed (117) hide show
  1. package/dist/668.js +2 -0
  2. package/dist/assets/031b9314092954f3.woff2 +0 -0
  3. package/dist/assets/031cf8d6851ae28b.woff2 +0 -0
  4. package/dist/assets/04e13675b1493ad2.woff2 +0 -0
  5. package/dist/assets/0519ad6f9869d898.woff2 +0 -0
  6. package/dist/assets/07c6d6ea9c229edb.woff +0 -0
  7. package/dist/assets/0a9edc5b190f2190.woff +0 -0
  8. package/dist/assets/0ccfdf89065a00b3.woff2 +0 -0
  9. package/dist/assets/0ce1ebd07c368f63.woff +0 -0
  10. package/dist/assets/1192b38e490fc7d1.woff2 +0 -0
  11. package/dist/assets/17e097f3b9f2d542.woff2 +0 -0
  12. package/dist/assets/19f91f1ad9824715.woff +0 -0
  13. package/dist/assets/1cc7496cc9b77e08.woff +0 -0
  14. package/dist/assets/1e592275a4fc2c99.woff2 +0 -0
  15. package/dist/assets/1e8de1180277cf53.woff +0 -0
  16. package/dist/assets/21b7c92d576179bb.woff2 +0 -0
  17. package/dist/assets/259c166b717079d8.woff +0 -0
  18. package/dist/assets/30ec7aec36351a14.woff +0 -0
  19. package/dist/assets/318ac720200f56ad.svg +1 -0
  20. package/dist/assets/3372ffe2ab723644.woff +0 -0
  21. package/dist/assets/36927296f7219149.woff2 +0 -0
  22. package/dist/assets/3806f0522558b224.woff2 +0 -0
  23. package/dist/assets/3c6c2126b6583695.woff2 +0 -0
  24. package/dist/assets/3d62b6f4c938e2e0.woff +0 -0
  25. package/dist/assets/3f48d5c9b4d1724f.woff +0 -0
  26. package/dist/assets/4021a38ee294b169.png +0 -0
  27. package/dist/assets/434c501c034ff4d7.woff2 +0 -0
  28. package/dist/assets/43cee8b32aebce11.woff +0 -0
  29. package/dist/assets/456562a2e1e13e20.woff +0 -0
  30. package/dist/assets/48d247e34d3aa635.woff +0 -0
  31. package/dist/assets/495dffa7dcac87c7.woff +0 -0
  32. package/dist/assets/4a386aca9584dbb9.woff2 +0 -0
  33. package/dist/assets/4b70338a5df3d413.woff2 +0 -0
  34. package/dist/assets/4cc1ace7e0d08476.woff +0 -0
  35. package/dist/assets/5858323bed0fe4bc.woff +0 -0
  36. package/dist/assets/59a71b9c0e14a00c.woff2 +0 -0
  37. package/dist/assets/619287de139b93ac.woff +0 -0
  38. package/dist/assets/62df8e180451dc9c.woff2 +0 -0
  39. package/dist/assets/630c5ad5139b5844.woff2 +0 -0
  40. package/dist/assets/6690f2dc3ac60371.woff2 +0 -0
  41. package/dist/assets/69426761a47f790e.woff2 +0 -0
  42. package/dist/assets/69c066cbc1e388a8.svg +1 -0
  43. package/dist/assets/6bc65973da12e0db.woff2 +0 -0
  44. package/dist/assets/6c5480c146b7fec6.woff +0 -0
  45. package/dist/assets/6efba251d9ff16f0.woff +0 -0
  46. package/dist/assets/6f2be5c4e077a95f.woff +0 -0
  47. package/dist/assets/736e673b62aec3a1.woff +0 -0
  48. package/dist/assets/786c2167e5fb0419.woff2 +0 -0
  49. package/dist/assets/78dd43210d89bfa0.woff +0 -0
  50. package/dist/assets/790c228262b3cc43.woff +0 -0
  51. package/dist/assets/793b729fcc55fb15.woff2 +0 -0
  52. package/dist/assets/7a5dc43a36101231.woff2 +0 -0
  53. package/dist/assets/7a893d1eb7679380.woff +0 -0
  54. package/dist/assets/7a99187126461071.woff +0 -0
  55. package/dist/assets/7d6d8a6f02c4c1aa.woff +0 -0
  56. package/dist/assets/7f7357dc812eefda.woff +0 -0
  57. package/dist/assets/871c3ceece4e3cd9.woff +0 -0
  58. package/dist/assets/87f3dff3547b0909.woff2 +0 -0
  59. package/dist/assets/87f95ed67632b03b.woff2 +0 -0
  60. package/dist/assets/89d075654f06f10c.woff2 +0 -0
  61. package/dist/assets/8c4d36f4ee8e7c52.woff +0 -0
  62. package/dist/assets/8cfbfbd3d549aa8f.woff2 +0 -0
  63. package/dist/assets/901509487406193c.woff +0 -0
  64. package/dist/assets/937a484c67327d90.woff +0 -0
  65. package/dist/assets/9999b0f2b2092b76.woff +0 -0
  66. package/dist/assets/99acac18e078b66e.woff +0 -0
  67. package/dist/assets/99ad1c88b9cdd54d.woff2 +0 -0
  68. package/dist/assets/99df3ad791ebae4d.woff +0 -0
  69. package/dist/assets/9bcd290ba4712876.woff2 +0 -0
  70. package/dist/assets/9f7ce8788b3a2feb.woff +0 -0
  71. package/dist/assets/a09ffd2fa9db2b77.woff2 +0 -0
  72. package/dist/assets/a11e030888b0c74d.woff2 +0 -0
  73. package/dist/assets/a221c5c63b0b007f.woff2 +0 -0
  74. package/dist/assets/a2b67360075a3845.woff2 +0 -0
  75. package/dist/assets/a995d3bd798f6af6.woff +0 -0
  76. package/dist/assets/a9a8664294faf616.woff2 +0 -0
  77. package/dist/assets/ac778417aa085869.png +0 -0
  78. package/dist/assets/af1dafcfb9d93cb7.ttf +0 -0
  79. package/dist/assets/b6f749506db82948.woff2 +0 -0
  80. package/dist/assets/b83e01be56fee57a.woff2 +0 -0
  81. package/dist/assets/bb96a486b115a27e.woff2 +0 -0
  82. package/dist/assets/bd6455e315f82d54.woff +0 -0
  83. package/dist/assets/c0cd43646bf5bc8e.woff2 +0 -0
  84. package/dist/assets/c8c031dea2283941.woff2 +0 -0
  85. package/dist/assets/c8de52c3f3327f69.woff +0 -0
  86. package/dist/assets/cb4e4e5d92737be1.woff2 +0 -0
  87. package/dist/assets/cc800fd19d5badfe.woff2 +0 -0
  88. package/dist/assets/d3306554cd238326.woff2 +0 -0
  89. package/dist/assets/d697bdae42ff838a.woff2 +0 -0
  90. package/dist/assets/d89041b1647c76f8.woff2 +0 -0
  91. package/dist/assets/dade5e8991a4748b.woff +0 -0
  92. package/dist/assets/db49dd71ad0fd177.woff2 +0 -0
  93. package/dist/assets/deaeec314b032fd9.woff +0 -0
  94. package/dist/assets/df18386e29f35837.ttf +0 -0
  95. package/dist/assets/e14b7a3b443b8c88.woff +0 -0
  96. package/dist/assets/e4cd99ec6cee4d80.woff +0 -0
  97. package/dist/assets/e6648178fa173da7.woff +0 -0
  98. package/dist/assets/e81332fec9311063.woff2 +0 -0
  99. package/dist/assets/ef28e132822430d7.woff +0 -0
  100. package/dist/assets/f2d64f400f75f079.woff +0 -0
  101. package/dist/assets/f6e1854c7f798a3a.woff +0 -0
  102. package/dist/assets/f7589cf6b9bf4073.woff +0 -0
  103. package/dist/assets/f87c7e0970223449.woff2 +0 -0
  104. package/dist/backend/cli.mjs +3586 -0
  105. package/dist/favicon.png +0 -0
  106. package/dist/index.html +12 -0
  107. package/dist/main.css +2 -0
  108. package/dist/main.js +152 -0
  109. package/dist/mcp-page-client.js +13 -0
  110. package/dist/mcp-page-console.js +2 -0
  111. package/dist/runtime.405c167245800bcf.hot-update.js +9 -0
  112. package/dist/runtime.js +1285 -0
  113. package/package.json +98 -0
  114. package/src/shared/modes.mjs +319 -0
  115. package/src/shared/modes.spec.js +87 -0
  116. package/src/shared/modes.spec.mjs +95 -0
  117. package/src/shared/tabs.mjs +7 -0
package/package.json ADDED
@@ -0,0 +1,98 @@
1
+ {
2
+ "name": "@livepreso/cdk",
3
+ "version": "0.0.1",
4
+ "description": "Content Development Kit",
5
+ "bin": {
6
+ "livepreso-cdk": "./dist/backend/cli.mjs"
7
+ },
8
+ "files": [
9
+ "dist/*.css",
10
+ "dist/*.js",
11
+ "dist/*.LICENSE.txt",
12
+ "dist/index.html",
13
+ "dist/favicon.png",
14
+ "dist/assets",
15
+ "dist/backend",
16
+ "src/shared",
17
+ "!src/shared/*.spec.*"
18
+ ],
19
+ "devDependencies": {
20
+ "html-webpack-plugin": "~5.5.3",
21
+ "expose-loader": "~4.1.0",
22
+ "webpack-merge": "~5.9.0",
23
+ "css-loader": "~6.8.1",
24
+ "postcss-loader": "~7.3.3",
25
+ "sass-loader": "~13.3.2",
26
+ "style-loader": "~3.3.3",
27
+ "@babel/preset-env": "~7.22.10",
28
+ "@babel/preset-react": "~7.25.9",
29
+ "react-refresh": "~0.14.0",
30
+ "eslint": "~9.15.0",
31
+ "jest": "~29.7.0",
32
+ "babel-jest": "~29.7.0",
33
+ "@babel/core": "~7.26.0",
34
+ "jest-environment-jsdom": "~29.7.0",
35
+ "@testing-library/react-hooks": "~8.0.1",
36
+ "@testing-library/react": "~16.3.0",
37
+ "path-browserify": "~1.0.1",
38
+ "react-query": "~3.39.3",
39
+ "react": "~19.2.0",
40
+ "react-dom": "~19.2.0",
41
+ "@tanstack/react-query": "~5.83.0",
42
+ "@tanstack/react-query-devtools": "~5.83.0",
43
+ "events": "~3.3.0",
44
+ "react-router-dom": "~6.15.0",
45
+ "@emotion/react": "~11.14.0",
46
+ "@emotion/styled": "~11.14.1",
47
+ "@mui/icons-material": "~7.3.6",
48
+ "react-complex-tree": "~2.2.2",
49
+ "jotai": "~2.17.0",
50
+ "jotai-effect": "~0.5.0",
51
+ "@kvs/indexeddb": "~2.1.4",
52
+ "jquery": "2.2.4",
53
+ "babel-plugin-import": "~1.13.8",
54
+ "@mui/material": "~7.3.6",
55
+ "motion": "~13.2.0",
56
+ "@rspack/cli": "2.2.1",
57
+ "@rspack/core": "2.2.1",
58
+ "@rspack/dev-server": "2.2.1",
59
+ "@rspack/plugin-react-refresh": "2.0.2",
60
+ "sp-get-port-by-name": "0.0.1",
61
+ "@livepreso/eslint-config": "1.0.0",
62
+ "@livepreso/presenter": "2.50.3",
63
+ "sp-editable-components": "1.7.2",
64
+ "sp-components": "3.1.1",
65
+ "@livepreso/deck-interface": "0.0.1"
66
+ },
67
+ "dependencies": {
68
+ "@modelcontextprotocol/sdk": "~1.29.0",
69
+ "@fastify/websocket": "~11.2.0",
70
+ "zod": "~4.4.3",
71
+ "dedent-js": "~1.0.1",
72
+ "modern-screenshot": "~4.7.0",
73
+ "fast-glob": "~3.3.2",
74
+ "smol-toml": "~1.1.4",
75
+ "portscanner": "~2.2.0",
76
+ "commander": "~12.0.0",
77
+ "yamljs": "~0.3.0",
78
+ "handle-cli-error": "~5.0.0",
79
+ "fs-extra": "~11.2.0",
80
+ "consola": "~3.2.3",
81
+ "@mui/base": "~5.0.0-beta.61",
82
+ "lodash.get": "~4.4.2",
83
+ "lodash.debounce": "~4.0.8",
84
+ "@fontsource/roboto": "~5.1.0",
85
+ "fastify": "~5.8.5",
86
+ "@fastify/cors": "~10.0.0",
87
+ "@fastify/static": "~8.0.0",
88
+ "jsondiffpatch": "~0.6.0",
89
+ "@livepreso/api": "6.58.2"
90
+ },
91
+ "scripts": {
92
+ "serve": "rspack serve --config webpack.development.js --env development",
93
+ "build:production": "rspack build --config webpack.production.js",
94
+ "test": "jest",
95
+ "coverage": "jest --collect-coverage",
96
+ "build": ""
97
+ }
98
+ }
@@ -0,0 +1,319 @@
1
+ // Shared by the app and the dev server (the MCP mode tools), so this file is
2
+ // .mjs: the backend imports it directly with Node's ESM loader.
3
+ import { SLIDES, TABS, TEMPLATES } from "./tabs.mjs";
4
+
5
+ /** Where a mode keeps what is typed into it. */
6
+ export const CMS_VALS = "cmsVals";
7
+
8
+ export const CONTEXT_OVERRIDES = "contextOverrides";
9
+
10
+ /** Where a template copy keeps both its companywide and its personal values. */
11
+ export const TEMPLATE_CONTEXT = "templateContext";
12
+
13
+ // The instance `placement` reports, which is what a caller with no template in
14
+ // hand sees. Each template drawn on the tab is given a number of its own.
15
+ const REPORTED_INSTANCE = 1;
16
+
17
+ export const PRESENT_STATES = [
18
+ {
19
+ title: "App",
20
+ key: "app",
21
+ description: "Replicate various areas in the app",
22
+ childrenDescription: "Which app screen",
23
+ children: [
24
+ {
25
+ title: "Preso",
26
+ key: "preso",
27
+ description: "Screens for a preso",
28
+ childrenDescription: "Preso present types",
29
+ editStore: CONTEXT_OVERRIDES,
30
+ children: [
31
+ {
32
+ title: "Prep",
33
+ key: "prep",
34
+ description:
35
+ "Test preparing a preso - contains editables and the like usually",
36
+ bodyClasses: ["master", "omnipreso", "livepreso"],
37
+ tabs: [SLIDES],
38
+ childrenDescription: "Prepping or previewing",
39
+ children: [
40
+ {
41
+ title: "Prepping",
42
+ key: "prepping",
43
+ bodyClasses: ["preview"],
44
+ showEditables: true,
45
+ },
46
+ {
47
+ title: "Previewing",
48
+ key: "previewing",
49
+ bodyClasses: ["present"],
50
+ },
51
+ ],
52
+ },
53
+ {
54
+ title: "Add slides",
55
+ key: "add-slides",
56
+ description: "Test a template in various stages",
57
+ bodyClasses: ["master", "omnipreso", "livepreso"],
58
+ tabs: [TEMPLATES],
59
+ children: [
60
+ {
61
+ title: "Template preview",
62
+ key: "template-preview",
63
+ description: "A read-only view of a template",
64
+ bodyClasses: ["edit-mode"],
65
+ editStore: null,
66
+ providesCmsVals: false,
67
+ },
68
+ {
69
+ title: "User template",
70
+ key: "user-template",
71
+ description: "A template override owned by a salesperson",
72
+ bodyClasses: ["edit-mode"],
73
+ showEditables: true,
74
+ editStore: TEMPLATE_CONTEXT,
75
+ buildPlacement: (instance) => ({
76
+ createdByTemplate: true,
77
+ templateID: instance,
78
+ }),
79
+ },
80
+ {
81
+ title: "Unsaved custom slide",
82
+ key: "custom-slide",
83
+ description: "A custom slide dropped in, before it is uploaded",
84
+ bodyClasses: ["edit-mode"],
85
+ showEditables: true,
86
+ editStore: TEMPLATE_CONTEXT,
87
+ buildPlacement: (instance) => ({
88
+ createdByTemplate: true,
89
+ custom: true,
90
+ willUpload: true,
91
+ id: instance,
92
+ }),
93
+ },
94
+ {
95
+ title: "Saved custom slide",
96
+ key: "custom-slide-saved",
97
+ description: "A custom slide dropped in, once it is uploaded",
98
+ bodyClasses: ["edit-mode"],
99
+ showEditables: true,
100
+ editStore: TEMPLATE_CONTEXT,
101
+ buildPlacement: (instance) => ({
102
+ createdByTemplate: true,
103
+ custom: true,
104
+ adjunct: { id: instance },
105
+ }),
106
+ },
107
+ ],
108
+ },
109
+ {
110
+ title: "Present",
111
+ key: "present",
112
+ description: "Test how it will be presented to customers",
113
+ bodyClasses: ["master", "omnipreso", "present", "livepreso"],
114
+ tabs: [SLIDES],
115
+ },
116
+ {
117
+ title: "Review",
118
+ key: "review",
119
+ description: "Test how it looks after the preso has concluded",
120
+ bodyClasses: ["master", "omnipreso", "review", "livepreso"],
121
+ editStore: null,
122
+ tabs: [SLIDES],
123
+ },
124
+ ],
125
+ },
126
+ {
127
+ title: "PresoManager",
128
+ key: "presomanager",
129
+ description: "For testing deck-wide editable values and templates",
130
+ childrenDescription: "Which type of preview",
131
+ bodyClasses: ["master", "review", "livepreso", "presomanager"],
132
+ editStore: CMS_VALS,
133
+ children: [
134
+ {
135
+ title: "Edit mode",
136
+ key: "edit",
137
+ bodyClasses: ["edit-mode"],
138
+ showEditables: true,
139
+ tabs: [SLIDES],
140
+ },
141
+ {
142
+ title: "Empty preview",
143
+ key: "preview",
144
+ bodyClasses: ["empty-preview"],
145
+ tabs: [SLIDES],
146
+ },
147
+ {
148
+ title: "Template preview",
149
+ key: "template-preview",
150
+ description: "A read-only view of a template",
151
+ bodyClasses: ["edit-mode"],
152
+ editStore: null,
153
+ providesCmsVals: false,
154
+ tabs: [TEMPLATES],
155
+ },
156
+ {
157
+ title: "Unsaved placed template",
158
+ key: "placed-template",
159
+ description: "A template placed as a slide, before it is published",
160
+ bodyClasses: ["edit-mode"],
161
+ showEditables: true,
162
+ // PresoManager uses an "<n>-temp" id until the server assigns a
163
+ // real one on publish.
164
+ buildPlacement: (instance) => ({
165
+ createdByTemplate: true,
166
+ autoAdjunctID: `${instance}-temp`,
167
+ }),
168
+ tabs: [TEMPLATES],
169
+ },
170
+ {
171
+ title: "Saved placed template",
172
+ key: "placed-template-saved",
173
+ description: "A template placed as a slide, once it is published",
174
+ bodyClasses: ["edit-mode"],
175
+ showEditables: true,
176
+ buildPlacement: (instance) => ({
177
+ createdByTemplate: true,
178
+ autoAdjunctID: instance,
179
+ }),
180
+ tabs: [TEMPLATES],
181
+ },
182
+ ],
183
+ },
184
+ {
185
+ title: "Preset",
186
+ key: "preset",
187
+ description: "For testing a preset preview",
188
+ bodyClasses: ["review", "master", "livepreso", "empty-preview"],
189
+ editStore: CMS_VALS,
190
+ isReadOnly: true,
191
+ tabs: [SLIDES],
192
+ },
193
+ ],
194
+ },
195
+ {
196
+ title: "Link",
197
+ key: "link",
198
+ description:
199
+ "Links of various sorts for accessing LivePreso outside of the main app",
200
+ childrenDescription: "What type of link",
201
+ editStore: CONTEXT_OVERRIDES,
202
+ tabs: [SLIDES],
203
+ children: [
204
+ { title: "Share", key: "share", bodyClasses: ["share_online"] },
205
+ { title: "Remote", key: "remote", bodyClasses: ["client"] },
206
+ ],
207
+ },
208
+ {
209
+ title: "Screenshot",
210
+ key: "screenshot",
211
+ description: "Test how the preso looks for various screenshot types",
212
+ bodyClasses: ["screenshot", "share_online"],
213
+ childrenDescription: "What type of screenshot",
214
+ isScreenshot: true,
215
+ editStore: CONTEXT_OVERRIDES,
216
+ isReadOnly: true,
217
+ children: [
218
+ {
219
+ title: "Thumbnail",
220
+ key: "thumbnail",
221
+ bodyClasses: ["screenshot-thumbnail"],
222
+ },
223
+ { title: "PDF", key: "pdf", bodyClasses: ["screenshot-full"] },
224
+ ],
225
+ },
226
+ ];
227
+
228
+ /**
229
+ * The value the deepest state on the trail carries for this field.
230
+ */
231
+ function readNearest(states, field, fallback) {
232
+ const named = [...states].reverse().find((state) => field in state);
233
+
234
+ return named ? named[field] : fallback;
235
+ }
236
+
237
+ function collectModes(nodes, ancestors) {
238
+ const modes = [];
239
+
240
+ nodes.forEach((node, index) => {
241
+ const trail = [...ancestors, { node, index }];
242
+
243
+ if (node.children?.length) {
244
+ modes.push(...collectModes(node.children, trail));
245
+ return;
246
+ }
247
+
248
+ const nodes = trail.map((entry) => entry.node);
249
+ const described = [...nodes].reverse().find((state) => state.description);
250
+ const editStore = readNearest(nodes, "editStore", CMS_VALS);
251
+ const buildPlacement = readNearest(nodes, "buildPlacement", null);
252
+
253
+ // Flags are inherited: a state deep in the tree is in PresoManager, or
254
+ // showing editables, because one of the states it sits under says so.
255
+ modes.push({
256
+ path: nodes.map((state) => state.key).join("/"),
257
+ indices: trail.map((entry) => entry.index),
258
+ title: nodes.map((state) => state.title).join(" > "),
259
+ description: described ? described.description : node.title,
260
+ bodyClasses: nodes.flatMap((state) => state.bodyClasses ?? []),
261
+ showEditables: nodes.some((state) => state.showEditables),
262
+ isPresomanager: nodes.some((state) => state.key === "presomanager"),
263
+ isScreenshot: nodes.some((state) => state.key === "screenshot"),
264
+ isEmptyPreview: nodes.some((state) =>
265
+ state.bodyClasses?.includes("empty-preview"),
266
+ ),
267
+ tabs: readNearest(nodes, "tabs", TABS),
268
+ editStore,
269
+ isReadOnly: editStore === null || readNearest(nodes, "isReadOnly", false),
270
+ providesCmsVals: readNearest(nodes, "providesCmsVals", true),
271
+ buildPlacement,
272
+ // A plain object, because a mode is serialised over the MCP and read
273
+ // for its shape - which channel it stores on, whether it is a copy.
274
+ placement: buildPlacement ? buildPlacement(REPORTED_INSTANCE) : null,
275
+ });
276
+ });
277
+
278
+ return modes;
279
+ }
280
+
281
+ /**
282
+ * Every mode that can actually be selected: the leaves of PRESENT_STATES.
283
+ * Picking a parent in the CDK's state selector walks down to its first
284
+ * descendant until it reaches a leaf, so a leaf is the only thing ever stored.
285
+ *
286
+ * `path` is the slash-separated key trail, which is how modes are named
287
+ * outside the app. `indices` is the position of each step in its level, which
288
+ * is how the app stores the selection.
289
+ */
290
+ export const MODES = collectModes(PRESENT_STATES, []);
291
+
292
+ export function findModeByPath(path) {
293
+ return MODES.find((mode) => mode.path === path) ?? null;
294
+ }
295
+
296
+ export function findModeByIndices(indices) {
297
+ if (!Array.isArray(indices)) {
298
+ return null;
299
+ }
300
+
301
+ const wanted = indices.join(",");
302
+
303
+ return MODES.find((mode) => mode.indices.join(",") === wanted) ?? null;
304
+ }
305
+
306
+ /** The modes one tab offers, in the order the picker walks them. */
307
+ export function findModesForTab(tab) {
308
+ return MODES.filter((mode) => mode.tabs.includes(tab));
309
+ }
310
+
311
+ export function isStateOnTab(state, tab, inherited = TABS) {
312
+ const tabs = state.tabs ?? inherited;
313
+
314
+ if (state.children?.length) {
315
+ return state.children.some((child) => isStateOnTab(child, tab, tabs));
316
+ }
317
+
318
+ return tabs.includes(tab);
319
+ }
@@ -0,0 +1,87 @@
1
+ import {
2
+ MODES,
3
+ findModeByIndices,
4
+ findModeByPath,
5
+ PRESENT_STATES,
6
+ } from "./modes.mjs";
7
+
8
+ describe("MODES", () => {
9
+ it("only contains states with no children", () => {
10
+ const leaves = MODES.map((mode) => mode.path);
11
+
12
+ expect(leaves).toContain("app/preso/prep/prepping");
13
+ expect(leaves).not.toContain("app/preso/prep");
14
+ expect(leaves).not.toContain("app");
15
+ });
16
+
17
+ it("indexes each step by its position in PRESENT_STATES", () => {
18
+ const mode = findModeByPath("app/presomanager/edit");
19
+
20
+ expect(mode.indices).toEqual([0, 1, 0]);
21
+ expect(PRESENT_STATES[0].children[1].children[0].key).toBe("edit");
22
+ });
23
+
24
+ it("titles a mode with the states it came through", () => {
25
+ expect(findModeByPath("app/preso/prep/prepping").title).toBe(
26
+ "App > Preso > Prep > Prepping",
27
+ );
28
+ });
29
+
30
+ it("describes a mode with the nearest description above it", () => {
31
+ expect(findModeByPath("app/preso/prep/prepping").description).toBe(
32
+ "Test preparing a preso - contains editables and the like usually",
33
+ );
34
+ });
35
+
36
+ it("reports whether editables are shown", () => {
37
+ expect(findModeByPath("app/preso/prep/prepping").showEditables).toBe(true);
38
+ expect(findModeByPath("app/preso/prep/previewing").showEditables).toBe(
39
+ false,
40
+ );
41
+ });
42
+
43
+ it("offers no editables where a template is only being looked at", () => {
44
+ expect(
45
+ findModeByPath("app/preso/add-slides/template-preview").showEditables,
46
+ ).toBe(false);
47
+ expect(
48
+ findModeByPath("app/presomanager/template-preview").showEditables,
49
+ ).toBe(false);
50
+ });
51
+
52
+ it("inherits flags from the states above the leaf", () => {
53
+ expect(findModeByPath("app/presomanager/edit").isPresomanager).toBe(true);
54
+ expect(findModeByPath("screenshot/pdf").isScreenshot).toBe(true);
55
+ });
56
+
57
+ it("reports the modes rendering with no presentation behind them", () => {
58
+ expect(findModeByPath("app/presomanager/preview").isEmptyPreview).toBe(
59
+ true,
60
+ );
61
+ expect(findModeByPath("app/preset").isEmptyPreview).toBe(true);
62
+ });
63
+
64
+ it("leaves flags off modes outside those states", () => {
65
+ const present = findModeByPath("app/preso/present");
66
+
67
+ expect(present.isPresomanager).toBe(false);
68
+ expect(present.isScreenshot).toBe(false);
69
+ expect(present.isEmptyPreview).toBe(false);
70
+ });
71
+ });
72
+
73
+ describe("finding a mode", () => {
74
+ it("round trips between a path and indices", () => {
75
+ for (const mode of MODES) {
76
+ expect(findModeByIndices(mode.indices).path).toBe(mode.path);
77
+ }
78
+ });
79
+
80
+ it("returns null for an unknown path", () => {
81
+ expect(findModeByPath("app/nope")).toBeNull();
82
+ });
83
+
84
+ it("returns null for indices that stop above a leaf", () => {
85
+ expect(findModeByIndices([0, 0])).toBeNull();
86
+ });
87
+ });
@@ -0,0 +1,95 @@
1
+ import {
2
+ CMS_VALS,
3
+ CONTEXT_OVERRIDES,
4
+ findModeByPath,
5
+ findModesForTab,
6
+ isStateOnTab,
7
+ PRESENT_STATES,
8
+ } from "./modes.mjs";
9
+ import { SLIDES, TEMPLATES } from "./tabs.mjs";
10
+
11
+ function findState(key) {
12
+ return PRESENT_STATES[0].children.find((state) => state.key === key);
13
+ }
14
+
15
+ describe("findModesForTab", () => {
16
+ it("should offer the templates tab one mode per way the app shows a template", () => {
17
+ expect(findModesForTab(TEMPLATES).map((mode) => mode.path)).toEqual([
18
+ "app/preso/add-slides/template-preview",
19
+ "app/preso/add-slides/user-template",
20
+ "app/preso/add-slides/custom-slide",
21
+ "app/preso/add-slides/custom-slide-saved",
22
+ "app/presomanager/template-preview",
23
+ "app/presomanager/placed-template",
24
+ "app/presomanager/placed-template-saved",
25
+ "screenshot/thumbnail",
26
+ "screenshot/pdf",
27
+ ]);
28
+ });
29
+
30
+ it("should keep a template mode off the slides tab", () => {
31
+ const paths = findModesForTab(SLIDES).map((mode) => mode.path);
32
+
33
+ expect(paths).not.toContain("app/presomanager/template-preview");
34
+ });
35
+
36
+ it("should offer a screenshot on both tabs", () => {
37
+ expect(findModeByPath("screenshot/thumbnail").tabs).toEqual([
38
+ SLIDES,
39
+ TEMPLATES,
40
+ ]);
41
+ });
42
+ });
43
+
44
+ describe("isStateOnTab", () => {
45
+ it("should offer a parent wherever a state under it is offered", () => {
46
+ expect(isStateOnTab(findState("presomanager"), TEMPLATES)).toBe(true);
47
+ });
48
+
49
+ it("should hide a parent whose states are all for the other tab", () => {
50
+ expect(isStateOnTab(findState("preso"), TEMPLATES)).toBe(true);
51
+ expect(isStateOnTab(findState("preset"), TEMPLATES)).toBe(false);
52
+ });
53
+
54
+ it("should pass a tab down to states that name none of their own", () => {
55
+ expect(isStateOnTab(findState("preso").children[0], TEMPLATES)).toBe(false);
56
+ });
57
+ });
58
+
59
+ describe("MODES", () => {
60
+ it("should keep a prep edit in the context and a PresoManager one in the cmsvals", () => {
61
+ expect(findModeByPath("app/preso/prep/prepping").editStore).toBe(
62
+ CONTEXT_OVERRIDES,
63
+ );
64
+ expect(findModeByPath("app/presomanager/edit").editStore).toBe(CMS_VALS);
65
+ });
66
+
67
+ it("should call a template preview read only", () => {
68
+ expect(findModeByPath("app/presomanager/template-preview").isReadOnly).toBe(
69
+ true,
70
+ );
71
+ });
72
+
73
+ it("should withhold the cmsvals from a template preview", () => {
74
+ expect(
75
+ findModeByPath("app/presomanager/template-preview").providesCmsVals,
76
+ ).toBe(false);
77
+ expect(
78
+ findModeByPath("app/preso/add-slides/template-preview").providesCmsVals,
79
+ ).toBe(false);
80
+ });
81
+
82
+ it("should pass the cmsvals to every other mode", () => {
83
+ expect(findModeByPath("app/presomanager/edit").providesCmsVals).toBe(true);
84
+ });
85
+
86
+ it("should place a saved instance under an autoadjunct", () => {
87
+ expect(
88
+ findModeByPath("app/presomanager/placed-template-saved").placement,
89
+ ).toEqual({ createdByTemplate: true, autoAdjunctID: 1 });
90
+ });
91
+
92
+ it("should leave a slide the deck declares unplaced", () => {
93
+ expect(findModeByPath("app/presomanager/edit").placement).toBeNull();
94
+ });
95
+ });
@@ -0,0 +1,7 @@
1
+ // Which half of a deck the stage is showing. Shared by the app and the dev
2
+ // server, so this file is .mjs alongside `modes.mjs`.
3
+ export const SLIDES = "slides";
4
+
5
+ export const TEMPLATES = "templates";
6
+
7
+ export const TABS = [SLIDES, TEMPLATES];