@pantheon-systems/puck-css 0.4.2 → 0.4.4

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 (202) hide show
  1. package/dist/core/config.d.ts +3 -0
  2. package/dist/core/config.d.ts.map +1 -1
  3. package/dist/core/config.js +5 -6
  4. package/dist/core/config.js.map +1 -1
  5. package/dist/core/featureConfig.d.ts +2 -0
  6. package/dist/core/featureConfig.d.ts.map +1 -1
  7. package/dist/core/featureConfig.js +4 -0
  8. package/dist/core/featureConfig.js.map +1 -1
  9. package/dist/core/types.d.ts +58 -1
  10. package/dist/core/types.d.ts.map +1 -1
  11. package/dist/data/dal/index.d.ts +5 -1
  12. package/dist/data/dal/index.d.ts.map +1 -1
  13. package/dist/data/dal/index.js +22 -1
  14. package/dist/data/dal/index.js.map +1 -1
  15. package/dist/data/dal/init.d.ts.map +1 -1
  16. package/dist/data/dal/init.js +22 -14
  17. package/dist/data/dal/init.js.map +1 -1
  18. package/dist/data/dal/p1-store.d.ts +15 -1
  19. package/dist/data/dal/p1-store.d.ts.map +1 -1
  20. package/dist/data/dal/p1-store.js +51 -5
  21. package/dist/data/dal/p1-store.js.map +1 -1
  22. package/dist/data/dal/types.d.ts +13 -1
  23. package/dist/data/dal/types.d.ts.map +1 -1
  24. package/dist/data/page-store.d.ts +17 -2
  25. package/dist/data/page-store.d.ts.map +1 -1
  26. package/dist/data/page-store.js +47 -5
  27. package/dist/data/page-store.js.map +1 -1
  28. package/dist/data/route-templates.js +1 -1
  29. package/dist/data/route-templates.js.map +1 -1
  30. package/dist/editor/P1App.d.ts.map +1 -1
  31. package/dist/editor/P1App.js +1 -1
  32. package/dist/editor/P1App.js.map +1 -1
  33. package/dist/editor/P1PuckProvider.d.ts.map +1 -1
  34. package/dist/editor/P1PuckProvider.js +175 -66
  35. package/dist/editor/P1PuckProvider.js.map +1 -1
  36. package/dist/editor/plugin/P1Plugin.d.ts +16 -1
  37. package/dist/editor/plugin/P1Plugin.d.ts.map +1 -1
  38. package/dist/editor/plugin/P1Plugin.js +35 -4
  39. package/dist/editor/plugin/P1Plugin.js.map +1 -1
  40. package/dist/editor/plugin/createP1Overrides.d.ts.map +1 -1
  41. package/dist/editor/plugin/createP1Overrides.js +4 -1
  42. package/dist/editor/plugin/createP1Overrides.js.map +1 -1
  43. package/dist/editor/useDocuments.d.ts +4 -1
  44. package/dist/editor/useDocuments.d.ts.map +1 -1
  45. package/dist/editor/useDocuments.js +5 -2
  46. package/dist/editor/useDocuments.js.map +1 -1
  47. package/dist/editor/useP1Editor.d.ts +12 -0
  48. package/dist/editor/useP1Editor.d.ts.map +1 -1
  49. package/dist/editor/useP1Editor.js +40 -5
  50. package/dist/editor/useP1Editor.js.map +1 -1
  51. package/dist/editor/useP1Plugin.d.ts +1 -1
  52. package/dist/editor/useP1Plugin.d.ts.map +1 -1
  53. package/dist/editor/useP1Plugin.js +2 -0
  54. package/dist/editor/useP1Plugin.js.map +1 -1
  55. package/dist/editor/useRealtime.d.ts +9 -4
  56. package/dist/editor/useRealtime.d.ts.map +1 -1
  57. package/dist/editor/useRealtime.js +11 -6
  58. package/dist/editor/useRealtime.js.map +1 -1
  59. package/dist/features/content-type-templates/editor/useTemplateEditor.d.ts +20 -0
  60. package/dist/features/content-type-templates/editor/useTemplateEditor.d.ts.map +1 -0
  61. package/dist/features/content-type-templates/editor/useTemplateEditor.js +62 -0
  62. package/dist/features/content-type-templates/editor/useTemplateEditor.js.map +1 -0
  63. package/dist/features/content-type-templates/editor/useTemplatePermissions.d.ts +7 -0
  64. package/dist/features/content-type-templates/editor/useTemplatePermissions.d.ts.map +1 -0
  65. package/dist/features/content-type-templates/editor/useTemplatePermissions.js +12 -0
  66. package/dist/features/content-type-templates/editor/useTemplatePermissions.js.map +1 -0
  67. package/dist/features/content-type-templates/editor/useTemplateScaffold.d.ts +19 -0
  68. package/dist/features/content-type-templates/editor/useTemplateScaffold.d.ts.map +1 -0
  69. package/dist/features/content-type-templates/editor/useTemplateScaffold.js +37 -0
  70. package/dist/features/content-type-templates/editor/useTemplateScaffold.js.map +1 -0
  71. package/dist/features/content-type-templates/hooks/useTemplateList.d.ts +41 -0
  72. package/dist/features/content-type-templates/hooks/useTemplateList.d.ts.map +1 -0
  73. package/dist/features/content-type-templates/hooks/useTemplateList.js +72 -0
  74. package/dist/features/content-type-templates/hooks/useTemplateList.js.map +1 -0
  75. package/dist/features/content-type-templates/index.d.ts +18 -0
  76. package/dist/features/content-type-templates/index.d.ts.map +1 -0
  77. package/dist/features/content-type-templates/index.js +13 -0
  78. package/dist/features/content-type-templates/index.js.map +1 -0
  79. package/dist/features/content-type-templates/permissions/createPuckPermissions.d.ts +68 -0
  80. package/dist/features/content-type-templates/permissions/createPuckPermissions.d.ts.map +1 -0
  81. package/dist/features/content-type-templates/permissions/createPuckPermissions.js +90 -0
  82. package/dist/features/content-type-templates/permissions/createPuckPermissions.js.map +1 -0
  83. package/dist/features/content-type-templates/permissions/role-permissions.d.ts +49 -0
  84. package/dist/features/content-type-templates/permissions/role-permissions.d.ts.map +1 -0
  85. package/dist/features/content-type-templates/permissions/role-permissions.js +79 -0
  86. package/dist/features/content-type-templates/permissions/role-permissions.js.map +1 -0
  87. package/dist/features/content-type-templates/permissions/useContentRole.d.ts +37 -0
  88. package/dist/features/content-type-templates/permissions/useContentRole.d.ts.map +1 -0
  89. package/dist/features/content-type-templates/permissions/useContentRole.js +34 -0
  90. package/dist/features/content-type-templates/permissions/useContentRole.js.map +1 -0
  91. package/dist/features/content-type-templates/permissions/useResolveContentRole.d.ts +38 -0
  92. package/dist/features/content-type-templates/permissions/useResolveContentRole.d.ts.map +1 -0
  93. package/dist/features/content-type-templates/permissions/useResolveContentRole.js +83 -0
  94. package/dist/features/content-type-templates/permissions/useResolveContentRole.js.map +1 -0
  95. package/dist/features/content-type-templates/stores/index.d.ts +9 -0
  96. package/dist/features/content-type-templates/stores/index.d.ts.map +1 -0
  97. package/dist/features/content-type-templates/stores/index.js +8 -0
  98. package/dist/features/content-type-templates/stores/index.js.map +1 -0
  99. package/dist/features/content-type-templates/stores/template-store-api.d.ts +17 -0
  100. package/dist/features/content-type-templates/stores/template-store-api.d.ts.map +1 -0
  101. package/dist/features/content-type-templates/stores/template-store-api.js +56 -0
  102. package/dist/features/content-type-templates/stores/template-store-api.js.map +1 -0
  103. package/dist/features/content-type-templates/stores/template-store.d.ts +54 -0
  104. package/dist/features/content-type-templates/stores/template-store.d.ts.map +1 -0
  105. package/dist/features/content-type-templates/stores/template-store.js +80 -0
  106. package/dist/features/content-type-templates/stores/template-store.js.map +1 -0
  107. package/dist/features/content-type-templates/types.d.ts +114 -0
  108. package/dist/features/content-type-templates/types.d.ts.map +1 -0
  109. package/dist/features/content-type-templates/types.js +7 -0
  110. package/dist/features/content-type-templates/types.js.map +1 -0
  111. package/dist/features/content-type-templates/ui/ActionBarPinButton.d.ts +3 -0
  112. package/dist/features/content-type-templates/ui/ActionBarPinButton.d.ts.map +1 -0
  113. package/dist/features/content-type-templates/ui/ActionBarPinButton.js +77 -0
  114. package/dist/features/content-type-templates/ui/ActionBarPinButton.js.map +1 -0
  115. package/dist/features/content-type-templates/ui/TemplateManagerOverlay.d.ts +18 -0
  116. package/dist/features/content-type-templates/ui/TemplateManagerOverlay.d.ts.map +1 -0
  117. package/dist/features/content-type-templates/ui/TemplateManagerOverlay.js +167 -0
  118. package/dist/features/content-type-templates/ui/TemplateManagerOverlay.js.map +1 -0
  119. package/dist/features/content-type-templates/ui/TemplatePinPanel.d.ts +18 -0
  120. package/dist/features/content-type-templates/ui/TemplatePinPanel.d.ts.map +1 -0
  121. package/dist/features/content-type-templates/ui/TemplatePinPanel.js +11 -0
  122. package/dist/features/content-type-templates/ui/TemplatePinPanel.js.map +1 -0
  123. package/dist/features/content-type-templates/ui/TemplateSelector.d.ts +41 -0
  124. package/dist/features/content-type-templates/ui/TemplateSelector.d.ts.map +1 -0
  125. package/dist/features/content-type-templates/ui/TemplateSelector.js +32 -0
  126. package/dist/features/content-type-templates/ui/TemplateSelector.js.map +1 -0
  127. package/dist/features/content-type-templates/ui/dataToTemplate.d.ts +25 -0
  128. package/dist/features/content-type-templates/ui/dataToTemplate.d.ts.map +1 -0
  129. package/dist/features/content-type-templates/ui/dataToTemplate.js +37 -0
  130. package/dist/features/content-type-templates/ui/dataToTemplate.js.map +1 -0
  131. package/dist/features/content-type-templates/validation/structural-validation.d.ts +29 -0
  132. package/dist/features/content-type-templates/validation/structural-validation.d.ts.map +1 -0
  133. package/dist/features/content-type-templates/validation/structural-validation.js +69 -0
  134. package/dist/features/content-type-templates/validation/structural-validation.js.map +1 -0
  135. package/dist/index.d.ts +8 -1
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +6 -1
  138. package/dist/index.js.map +1 -1
  139. package/dist/p1/editor/connect/connect-field-modal.d.ts.map +1 -1
  140. package/dist/p1/editor/connect/connect-field-modal.js +23 -1
  141. package/dist/p1/editor/connect/connect-field-modal.js.map +1 -1
  142. package/dist/p1/editor/connect/field-connect-plugin.d.ts.map +1 -1
  143. package/dist/p1/editor/connect/field-connect-plugin.js +2 -6
  144. package/dist/p1/editor/connect/field-connect-plugin.js.map +1 -1
  145. package/dist/p1/pages/conflict-resolution-panel.d.ts +17 -0
  146. package/dist/p1/pages/conflict-resolution-panel.d.ts.map +1 -0
  147. package/dist/p1/pages/conflict-resolution-panel.js +74 -0
  148. package/dist/p1/pages/conflict-resolution-panel.js.map +1 -0
  149. package/dist/p1/pages/content-type-template-list.d.ts +7 -0
  150. package/dist/p1/pages/content-type-template-list.d.ts.map +1 -0
  151. package/dist/p1/pages/content-type-template-list.js +108 -0
  152. package/dist/p1/pages/content-type-template-list.js.map +1 -0
  153. package/dist/p1/pages/create-content-type-form.d.ts +7 -0
  154. package/dist/p1/pages/create-content-type-form.d.ts.map +1 -0
  155. package/dist/p1/pages/create-content-type-form.js +102 -0
  156. package/dist/p1/pages/create-content-type-form.js.map +1 -0
  157. package/dist/p1/pages/create-page-form.d.ts +8 -1
  158. package/dist/p1/pages/create-page-form.d.ts.map +1 -1
  159. package/dist/p1/pages/create-page-form.js +67 -8
  160. package/dist/p1/pages/create-page-form.js.map +1 -1
  161. package/dist/p1/pages/create-template-form.d.ts +6 -1
  162. package/dist/p1/pages/create-template-form.d.ts.map +1 -1
  163. package/dist/p1/pages/create-template-form.js +61 -15
  164. package/dist/p1/pages/create-template-form.js.map +1 -1
  165. package/dist/p1/pages/hooks.d.ts +6 -1
  166. package/dist/p1/pages/hooks.d.ts.map +1 -1
  167. package/dist/p1/pages/hooks.js +13 -2
  168. package/dist/p1/pages/hooks.js.map +1 -1
  169. package/dist/p1/pages/index.d.ts +5 -0
  170. package/dist/p1/pages/index.d.ts.map +1 -1
  171. package/dist/p1/pages/index.js +5 -0
  172. package/dist/p1/pages/index.js.map +1 -1
  173. package/dist/p1/pages/migration-conflict-queue.d.ts +8 -0
  174. package/dist/p1/pages/migration-conflict-queue.d.ts.map +1 -0
  175. package/dist/p1/pages/migration-conflict-queue.js +62 -0
  176. package/dist/p1/pages/migration-conflict-queue.js.map +1 -0
  177. package/dist/p1/pages/migration-preview-panel.d.ts +12 -0
  178. package/dist/p1/pages/migration-preview-panel.d.ts.map +1 -0
  179. package/dist/p1/pages/migration-preview-panel.js +157 -0
  180. package/dist/p1/pages/migration-preview-panel.js.map +1 -0
  181. package/dist/p1/pages/migration-status-panel.d.ts +7 -0
  182. package/dist/p1/pages/migration-status-panel.d.ts.map +1 -0
  183. package/dist/p1/pages/migration-status-panel.js +198 -0
  184. package/dist/p1/pages/migration-status-panel.js.map +1 -0
  185. package/dist/p1/pages/structure-page.d.ts.map +1 -1
  186. package/dist/p1/pages/structure-page.js +75 -18
  187. package/dist/p1/pages/structure-page.js.map +1 -1
  188. package/dist/p1/pages/structure-tabs.d.ts +11 -0
  189. package/dist/p1/pages/structure-tabs.d.ts.map +1 -0
  190. package/dist/p1/pages/structure-tabs.js +45 -0
  191. package/dist/p1/pages/structure-tabs.js.map +1 -0
  192. package/dist/pds/components/P1EditorHeader.d.ts +6 -2
  193. package/dist/pds/components/P1EditorHeader.d.ts.map +1 -1
  194. package/dist/pds/components/P1EditorHeader.js +6 -3
  195. package/dist/pds/components/P1EditorHeader.js.map +1 -1
  196. package/dist/pds/components/PageNavigator.d.ts +7 -2
  197. package/dist/pds/components/PageNavigator.d.ts.map +1 -1
  198. package/dist/pds/components/PageNavigator.js +28 -7
  199. package/dist/pds/components/PageNavigator.js.map +1 -1
  200. package/dist/pds/components/PageNavigator.module.css +70 -0
  201. package/package.json +3 -3
  202. package/src/styles.css +331 -0
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Content Type Templates Feature
3
+ *
4
+ * Enables site admins to define structural templates for documents
5
+ * and enforce structural conformance via role-based permissions.
6
+ *
7
+ * Feature-gated via enableContentTypeTemplates flag (default: true).
8
+ */
9
+ export type { ContentRole, TemplateMetadata, TemplateComponent, Template, TemplateBinding, CreateTemplateParams, UpdateTemplateParams, TemplateDocument, } from './types.js';
10
+ export type { TemplateStore } from './stores/index.js';
11
+ export { createInMemoryTemplateStore, createApiTemplateStore } from './stores/index.js';
12
+ export type { ComponentPermissions } from './permissions/role-permissions.js';
13
+ export { getPermissionsForRole, canPerformStructuralAction, canEditProps, canOverrideUrl, mergePermissions, } from './permissions/role-permissions.js';
14
+ export type { UseContentRoleReturn } from './permissions/useContentRole.js';
15
+ export { useContentRole } from './permissions/useContentRole.js';
16
+ export type { UseResolveContentRoleOptions, UseResolveContentRoleReturn } from './permissions/useResolveContentRole.js';
17
+ export { useResolveContentRole, mapCssRoleToContentRole } from './permissions/useResolveContentRole.js';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/content-type-templates/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAExF,YAAY,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,MAAM,mCAAmC,CAAC;AAC3C,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,YAAY,EAAE,4BAA4B,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AACxH,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Content Type Templates Feature
3
+ *
4
+ * Enables site admins to define structural templates for documents
5
+ * and enforce structural conformance via role-based permissions.
6
+ *
7
+ * Feature-gated via enableContentTypeTemplates flag (default: true).
8
+ */
9
+ export { createInMemoryTemplateStore, createApiTemplateStore } from './stores/index.js';
10
+ export { getPermissionsForRole, canPerformStructuralAction, canEditProps, canOverrideUrl, mergePermissions, } from './permissions/role-permissions.js';
11
+ export { useContentRole } from './permissions/useContentRole.js';
12
+ export { useResolveContentRole, mapCssRoleToContentRole } from './permissions/useResolveContentRole.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/features/content-type-templates/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAGxF,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Puck Permissions Resolver
3
+ *
4
+ * Creates a resolvePermissions function for Puck that enforces template constraints.
5
+ */
6
+ import type { Template, ContentRole } from '../types.js';
7
+ /**
8
+ * Puck permission flags for a component.
9
+ */
10
+ export interface PuckPermissions {
11
+ /** Can edit component props */
12
+ edit: boolean;
13
+ /** Can drag/reorder component */
14
+ drag: boolean;
15
+ /** Can delete component */
16
+ delete: boolean;
17
+ /** Can insert new components */
18
+ insert: boolean;
19
+ /** Can duplicate component */
20
+ duplicate: boolean;
21
+ }
22
+ /**
23
+ * Item passed to resolvePermissions by Puck.
24
+ */
25
+ export interface PuckItem {
26
+ type: string;
27
+ }
28
+ /**
29
+ * App state passed to resolvePermissions by Puck.
30
+ */
31
+ export interface PuckAppState {
32
+ [key: string]: unknown;
33
+ }
34
+ /**
35
+ * Permission resolver function type for Puck.
36
+ */
37
+ export type PuckPermissionResolver = (item: PuckItem, appState: PuckAppState) => PuckPermissions;
38
+ /**
39
+ * Create a Puck permissions resolver based on template and user role.
40
+ *
41
+ * Permission logic:
42
+ * - **Pinned components**: drag=false, delete=false for all roles
43
+ * - **Non-pinned components**:
44
+ * - Admin/Editor: full permissions
45
+ * - Junior Editor: no structural permissions (drag/delete/insert/duplicate)
46
+ * - **Blank pages (no template)**:
47
+ * - Admin/Editor: full permissions
48
+ * - Junior Editor: no structural permissions
49
+ * - **Historical versions**: all structural permissions false for all roles
50
+ *
51
+ * @param template - Template this document is bound to (null for blank pages)
52
+ * @param role - User's content role
53
+ * @param isHistoricalVersion - Whether viewing a historical version (read-only)
54
+ * @returns Permission resolver function for Puck
55
+ *
56
+ * @example
57
+ * ```tsx
58
+ * const resolvePermissions = createPuckPermissions(template, 'editor', false);
59
+ *
60
+ * <Puck
61
+ * config={puckConfig}
62
+ * data={puckData}
63
+ * resolvePermissions={resolvePermissions}
64
+ * />
65
+ * ```
66
+ */
67
+ export declare function createPuckPermissions(template: Template | null, role: ContentRole, isHistoricalVersion: boolean): PuckPermissionResolver;
68
+ //# sourceMappingURL=createPuckPermissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPuckPermissions.d.ts","sourceRoot":"","sources":["../../../../src/features/content-type-templates/permissions/createPuckPermissions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,+BAA+B;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,iCAAiC;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,2BAA2B;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,gCAAgC;IAChC,MAAM,EAAE,OAAO,CAAC;IAChB,8BAA8B;IAC9B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAE3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACnC,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,YAAY,KACnB,eAAe,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EACzB,IAAI,EAAE,WAAW,EACjB,mBAAmB,EAAE,OAAO,GAC3B,sBAAsB,CA4DxB"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Puck Permissions Resolver
3
+ *
4
+ * Creates a resolvePermissions function for Puck that enforces template constraints.
5
+ */
6
+ /**
7
+ * Create a Puck permissions resolver based on template and user role.
8
+ *
9
+ * Permission logic:
10
+ * - **Pinned components**: drag=false, delete=false for all roles
11
+ * - **Non-pinned components**:
12
+ * - Admin/Editor: full permissions
13
+ * - Junior Editor: no structural permissions (drag/delete/insert/duplicate)
14
+ * - **Blank pages (no template)**:
15
+ * - Admin/Editor: full permissions
16
+ * - Junior Editor: no structural permissions
17
+ * - **Historical versions**: all structural permissions false for all roles
18
+ *
19
+ * @param template - Template this document is bound to (null for blank pages)
20
+ * @param role - User's content role
21
+ * @param isHistoricalVersion - Whether viewing a historical version (read-only)
22
+ * @returns Permission resolver function for Puck
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * const resolvePermissions = createPuckPermissions(template, 'editor', false);
27
+ *
28
+ * <Puck
29
+ * config={puckConfig}
30
+ * data={puckData}
31
+ * resolvePermissions={resolvePermissions}
32
+ * />
33
+ * ```
34
+ */
35
+ export function createPuckPermissions(template, role, isHistoricalVersion) {
36
+ return (item) => {
37
+ // Historical versions: all structural permissions false
38
+ if (isHistoricalVersion) {
39
+ return {
40
+ edit: true, // Can still view props in read-only mode
41
+ drag: false,
42
+ delete: false,
43
+ insert: false,
44
+ duplicate: false,
45
+ };
46
+ }
47
+ const juniorEditorRestricted = role === 'junior-editor';
48
+ // No template or template without components
49
+ if (!template || !template.components) {
50
+ return {
51
+ edit: true,
52
+ drag: !juniorEditorRestricted,
53
+ delete: !juniorEditorRestricted,
54
+ insert: !juniorEditorRestricted,
55
+ duplicate: !juniorEditorRestricted,
56
+ };
57
+ }
58
+ // Find component in template
59
+ const templateComponent = template.components.find((c) => c.type === item.type);
60
+ // Component not in template (user added it)
61
+ if (!templateComponent) {
62
+ return {
63
+ edit: true,
64
+ drag: !juniorEditorRestricted,
65
+ delete: !juniorEditorRestricted,
66
+ insert: !juniorEditorRestricted,
67
+ duplicate: !juniorEditorRestricted,
68
+ };
69
+ }
70
+ // Pinned component: locked for all roles
71
+ if (templateComponent.pinned) {
72
+ return {
73
+ edit: true,
74
+ drag: false,
75
+ delete: false,
76
+ insert: juniorEditorRestricted ? false : true,
77
+ duplicate: juniorEditorRestricted ? false : true,
78
+ };
79
+ }
80
+ // Non-pinned component in template
81
+ return {
82
+ edit: true,
83
+ drag: !juniorEditorRestricted,
84
+ delete: !juniorEditorRestricted,
85
+ insert: !juniorEditorRestricted,
86
+ duplicate: !juniorEditorRestricted,
87
+ };
88
+ };
89
+ }
90
+ //# sourceMappingURL=createPuckPermissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPuckPermissions.js","sourceRoot":"","sources":["../../../../src/features/content-type-templates/permissions/createPuckPermissions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2CH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAyB,EACzB,IAAiB,EACjB,mBAA4B;IAE5B,OAAO,CAAC,IAAc,EAAmB,EAAE;QACzC,wDAAwD;QACxD,IAAI,mBAAmB,EAAE,CAAC;YACxB,OAAO;gBACL,IAAI,EAAE,IAAI,EAAE,yCAAyC;gBACrD,IAAI,EAAE,KAAK;gBACX,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,KAAK;gBACb,SAAS,EAAE,KAAK;aACjB,CAAC;QACJ,CAAC;QAED,MAAM,sBAAsB,GAAG,IAAI,KAAK,eAAe,CAAC;QAExD,6CAA6C;QAC7C,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;YACtC,OAAO;gBACL,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,CAAC,sBAAsB;gBAC7B,MAAM,EAAE,CAAC,sBAAsB;gBAC/B,MAAM,EAAE,CAAC,sBAAsB;gBAC/B,SAAS,EAAE,CAAC,sBAAsB;aACnC,CAAC;QACJ,CAAC;QAED,6BAA6B;QAC7B,MAAM,iBAAiB,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC;QAEhF,4CAA4C;QAC5C,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACvB,OAAO;gBACL,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,CAAC,sBAAsB;gBAC7B,MAAM,EAAE,CAAC,sBAAsB;gBAC/B,MAAM,EAAE,CAAC,sBAAsB;gBAC/B,SAAS,EAAE,CAAC,sBAAsB;aACnC,CAAC;QACJ,CAAC;QAED,yCAAyC;QACzC,IAAI,iBAAiB,CAAC,MAAM,EAAE,CAAC;YAC7B,OAAO;gBACL,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,KAAK;gBACX,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;gBAC7C,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;aACjD,CAAC;QACJ,CAAC;QAED,mCAAmC;QACnC,OAAO;YACL,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,CAAC,sBAAsB;YAC7B,MAAM,EAAE,CAAC,sBAAsB;YAC/B,MAAM,EAAE,CAAC,sBAAsB;YAC/B,SAAS,EAAE,CAAC,sBAAsB;SACnC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Role-Based Permissions
3
+ *
4
+ * Permission calculations for content editing roles.
5
+ */
6
+ import type { ContentRole } from '../types.js';
7
+ /**
8
+ * Component-level permissions.
9
+ */
10
+ export interface ComponentPermissions {
11
+ /** Can add new components */
12
+ canAddComponents: boolean;
13
+ /** Can remove components */
14
+ canRemoveComponents: boolean;
15
+ /** Can move/reorder components */
16
+ canMoveComponents: boolean;
17
+ /** Can edit component props */
18
+ canEditProps: boolean;
19
+ /** Can override default URL pattern */
20
+ canOverrideUrl: boolean;
21
+ }
22
+ /**
23
+ * Get permissions for a content role.
24
+ *
25
+ * - admin: Full access - can create/edit templates, full structural control
26
+ * - editor: Pinned components locked (cannot move/delete), can add/remove non-pinned
27
+ * - junior-editor: View/edit props only, no structural changes
28
+ */
29
+ export declare function getPermissionsForRole(role: ContentRole): ComponentPermissions;
30
+ /**
31
+ * Check if a role can perform structural actions (add/remove/move components).
32
+ */
33
+ export declare function canPerformStructuralAction(role: ContentRole): boolean;
34
+ /**
35
+ * Check if a role can edit component props.
36
+ */
37
+ export declare function canEditProps(role: ContentRole): boolean;
38
+ /**
39
+ * Check if a role can override default URL pattern.
40
+ */
41
+ export declare function canOverrideUrl(role: ContentRole): boolean;
42
+ /**
43
+ * Merge template-based permissions with historical version lock.
44
+ *
45
+ * When viewing a historical version, all editing is disabled.
46
+ * This combines with role-based permissions to enforce the most restrictive policy.
47
+ */
48
+ export declare function mergePermissions(templatePerms: ComponentPermissions, isHistoricalVersion: boolean): ComponentPermissions;
49
+ //# sourceMappingURL=role-permissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-permissions.d.ts","sourceRoot":"","sources":["../../../../src/features/content-type-templates/permissions/role-permissions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6BAA6B;IAC7B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,4BAA4B;IAC5B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,kCAAkC;IAClC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,+BAA+B;IAC/B,YAAY,EAAE,OAAO,CAAC;IACtB,uCAAuC;IACvC,cAAc,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,GAAG,oBAAoB,CA2B7E;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAGrE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,oBAAoB,EACnC,mBAAmB,EAAE,OAAO,GAC3B,oBAAoB,CAatB"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Role-Based Permissions
3
+ *
4
+ * Permission calculations for content editing roles.
5
+ */
6
+ /**
7
+ * Get permissions for a content role.
8
+ *
9
+ * - admin: Full access - can create/edit templates, full structural control
10
+ * - editor: Pinned components locked (cannot move/delete), can add/remove non-pinned
11
+ * - junior-editor: View/edit props only, no structural changes
12
+ */
13
+ export function getPermissionsForRole(role) {
14
+ switch (role) {
15
+ case 'admin':
16
+ return {
17
+ canAddComponents: true,
18
+ canRemoveComponents: true,
19
+ canMoveComponents: true,
20
+ canEditProps: true,
21
+ canOverrideUrl: true,
22
+ };
23
+ case 'editor':
24
+ return {
25
+ canAddComponents: true,
26
+ canRemoveComponents: true,
27
+ canMoveComponents: true,
28
+ canEditProps: true,
29
+ canOverrideUrl: true,
30
+ };
31
+ case 'junior-editor':
32
+ return {
33
+ canAddComponents: false,
34
+ canRemoveComponents: false,
35
+ canMoveComponents: false,
36
+ canEditProps: true,
37
+ canOverrideUrl: false,
38
+ };
39
+ }
40
+ }
41
+ /**
42
+ * Check if a role can perform structural actions (add/remove/move components).
43
+ */
44
+ export function canPerformStructuralAction(role) {
45
+ const perms = getPermissionsForRole(role);
46
+ return perms.canAddComponents || perms.canRemoveComponents || perms.canMoveComponents;
47
+ }
48
+ /**
49
+ * Check if a role can edit component props.
50
+ */
51
+ export function canEditProps(role) {
52
+ return getPermissionsForRole(role).canEditProps;
53
+ }
54
+ /**
55
+ * Check if a role can override default URL pattern.
56
+ */
57
+ export function canOverrideUrl(role) {
58
+ return getPermissionsForRole(role).canOverrideUrl;
59
+ }
60
+ /**
61
+ * Merge template-based permissions with historical version lock.
62
+ *
63
+ * When viewing a historical version, all editing is disabled.
64
+ * This combines with role-based permissions to enforce the most restrictive policy.
65
+ */
66
+ export function mergePermissions(templatePerms, isHistoricalVersion) {
67
+ if (isHistoricalVersion) {
68
+ // Historical versions are read-only
69
+ return {
70
+ canAddComponents: false,
71
+ canRemoveComponents: false,
72
+ canMoveComponents: false,
73
+ canEditProps: false,
74
+ canOverrideUrl: false,
75
+ };
76
+ }
77
+ return templatePerms;
78
+ }
79
+ //# sourceMappingURL=role-permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-permissions.js","sourceRoot":"","sources":["../../../../src/features/content-type-templates/permissions/role-permissions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAiB;IACrD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,OAAO;YACV,OAAO;gBACL,gBAAgB,EAAE,IAAI;gBACtB,mBAAmB,EAAE,IAAI;gBACzB,iBAAiB,EAAE,IAAI;gBACvB,YAAY,EAAE,IAAI;gBAClB,cAAc,EAAE,IAAI;aACrB,CAAC;QACJ,KAAK,QAAQ;YACX,OAAO;gBACL,gBAAgB,EAAE,IAAI;gBACtB,mBAAmB,EAAE,IAAI;gBACzB,iBAAiB,EAAE,IAAI;gBACvB,YAAY,EAAE,IAAI;gBAClB,cAAc,EAAE,IAAI;aACrB,CAAC;QACJ,KAAK,eAAe;YAClB,OAAO;gBACL,gBAAgB,EAAE,KAAK;gBACvB,mBAAmB,EAAE,KAAK;gBAC1B,iBAAiB,EAAE,KAAK;gBACxB,YAAY,EAAE,IAAI;gBAClB,cAAc,EAAE,KAAK;aACtB,CAAC;IACN,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAAiB;IAC1D,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,KAAK,CAAC,gBAAgB,IAAI,KAAK,CAAC,mBAAmB,IAAI,KAAK,CAAC,iBAAiB,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,IAAiB;IAC5C,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAAiB;IAC9C,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,aAAmC,EACnC,mBAA4B;IAE5B,IAAI,mBAAmB,EAAE,CAAC;QACxB,oCAAoC;QACpC,OAAO;YACL,gBAAgB,EAAE,KAAK;YACvB,mBAAmB,EAAE,KAAK;YAC1B,iBAAiB,EAAE,KAAK;YACxB,YAAY,EAAE,KAAK;YACnB,cAAc,EAAE,KAAK;SACtB,CAAC;IACJ,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * useContentRole Hook
3
+ *
4
+ * React hook for managing content editing role and permissions.
5
+ */
6
+ import type { ContentRole } from '../types.js';
7
+ import { type ComponentPermissions } from './role-permissions.js';
8
+ /**
9
+ * Return value from useContentRole hook.
10
+ */
11
+ export interface UseContentRoleReturn {
12
+ /** Current content editing role */
13
+ role: ContentRole;
14
+ /** Computed permissions for the role */
15
+ permissions: ComponentPermissions;
16
+ }
17
+ /**
18
+ * Hook for managing content editing role and permissions.
19
+ *
20
+ * @param role - Content editing role (defaults to 'admin')
21
+ * @returns Current role and computed permissions
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * function Editor() {
26
+ * const { role, permissions } = useContentRole('editor');
27
+ *
28
+ * if (!permissions.canAddComponents) {
29
+ * return <div>Read-only mode</div>;
30
+ * }
31
+ *
32
+ * return <PuckEditor />;
33
+ * }
34
+ * ```
35
+ */
36
+ export declare function useContentRole(role?: ContentRole): UseContentRoleReturn;
37
+ //# sourceMappingURL=useContentRole.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useContentRole.d.ts","sourceRoot":"","sources":["../../../../src/features/content-type-templates/permissions/useContentRole.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAyB,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAEzF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,mCAAmC;IACnC,IAAI,EAAE,WAAW,CAAC;IAClB,wCAAwC;IACxC,WAAW,EAAE,oBAAoB,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAAC,IAAI,GAAE,WAAqB,GAAG,oBAAoB,CAOhF"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * useContentRole Hook
3
+ *
4
+ * React hook for managing content editing role and permissions.
5
+ */
6
+ import { useMemo } from 'react';
7
+ import { getPermissionsForRole } from './role-permissions.js';
8
+ /**
9
+ * Hook for managing content editing role and permissions.
10
+ *
11
+ * @param role - Content editing role (defaults to 'admin')
12
+ * @returns Current role and computed permissions
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * function Editor() {
17
+ * const { role, permissions } = useContentRole('editor');
18
+ *
19
+ * if (!permissions.canAddComponents) {
20
+ * return <div>Read-only mode</div>;
21
+ * }
22
+ *
23
+ * return <PuckEditor />;
24
+ * }
25
+ * ```
26
+ */
27
+ export function useContentRole(role = 'admin') {
28
+ const permissions = useMemo(() => getPermissionsForRole(role), [role]);
29
+ return {
30
+ role,
31
+ permissions,
32
+ };
33
+ }
34
+ //# sourceMappingURL=useContentRole.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useContentRole.js","sourceRoot":"","sources":["../../../../src/features/content-type-templates/permissions/useContentRole.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,qBAAqB,EAA6B,MAAM,uBAAuB,CAAC;AAYzF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,cAAc,CAAC,OAAoB,OAAO;IACxD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEvE,OAAO;QACL,IAAI;QACJ,WAAW;KACZ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * useResolveContentRole Hook
3
+ *
4
+ * Auto-detects the user's ContentRole by querying the CSS backend's
5
+ * auth/me endpoint with site context. Falls back to the provided
6
+ * default role if the backend doesn't return role info.
7
+ *
8
+ * CSS backend role mapping:
9
+ * - ADMIN → 'admin'
10
+ * - EDITOR → 'editor'
11
+ * - VIEWER → 'junior-editor' (read-only structural access)
12
+ * - NO_ACCESS → 'junior-editor' (most restrictive)
13
+ */
14
+ import type { ContentRole } from '../types.js';
15
+ type CssRoleName = 'ADMIN' | 'EDITOR' | 'VIEWER' | 'NO_ACCESS';
16
+ declare function mapCssRoleToContentRole(cssRole: CssRoleName): ContentRole;
17
+ export interface UseResolveContentRoleOptions {
18
+ baseUrl: string;
19
+ siteId: string;
20
+ branchId: string;
21
+ token: string | null;
22
+ fallbackRole?: ContentRole;
23
+ }
24
+ export interface UseResolveContentRoleReturn {
25
+ role: ContentRole;
26
+ loading: boolean;
27
+ resolved: boolean;
28
+ }
29
+ /**
30
+ * Hook to auto-resolve the user's ContentRole from the CSS backend.
31
+ *
32
+ * Calls GET /api/sites/{siteId}/auth/role (when available) to determine
33
+ * the user's effective role. Falls back to the provided fallbackRole
34
+ * if the endpoint is unavailable or returns an error.
35
+ */
36
+ export declare function useResolveContentRole({ baseUrl, siteId, branchId, token, fallbackRole, }: UseResolveContentRoleOptions): UseResolveContentRoleReturn;
37
+ export { mapCssRoleToContentRole };
38
+ //# sourceMappingURL=useResolveContentRole.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useResolveContentRole.d.ts","sourceRoot":"","sources":["../../../../src/features/content-type-templates/permissions/useResolveContentRole.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,KAAK,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE/D,iBAAS,uBAAuB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,CAWlE;AAED,MAAM,WAAW,4BAA4B;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B;AAED,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,OAAO,EACP,MAAM,EACN,QAAQ,EACR,KAAK,EACL,YAA8B,GAC/B,EAAE,4BAA4B,GAAG,2BAA2B,CAkD5D;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * useResolveContentRole Hook
3
+ *
4
+ * Auto-detects the user's ContentRole by querying the CSS backend's
5
+ * auth/me endpoint with site context. Falls back to the provided
6
+ * default role if the backend doesn't return role info.
7
+ *
8
+ * CSS backend role mapping:
9
+ * - ADMIN → 'admin'
10
+ * - EDITOR → 'editor'
11
+ * - VIEWER → 'junior-editor' (read-only structural access)
12
+ * - NO_ACCESS → 'junior-editor' (most restrictive)
13
+ */
14
+ import { useState, useEffect } from 'react';
15
+ function mapCssRoleToContentRole(cssRole) {
16
+ switch (cssRole) {
17
+ case 'ADMIN':
18
+ return 'admin';
19
+ case 'EDITOR':
20
+ return 'editor';
21
+ case 'VIEWER':
22
+ case 'NO_ACCESS':
23
+ default:
24
+ return 'junior-editor';
25
+ }
26
+ }
27
+ /**
28
+ * Hook to auto-resolve the user's ContentRole from the CSS backend.
29
+ *
30
+ * Calls GET /api/sites/{siteId}/auth/role (when available) to determine
31
+ * the user's effective role. Falls back to the provided fallbackRole
32
+ * if the endpoint is unavailable or returns an error.
33
+ */
34
+ export function useResolveContentRole({ baseUrl, siteId, branchId, token, fallbackRole = 'junior-editor', }) {
35
+ const [role, setRole] = useState(fallbackRole);
36
+ const [loading, setLoading] = useState(true);
37
+ const [resolved, setResolved] = useState(false);
38
+ useEffect(() => {
39
+ if (!baseUrl || !siteId || !token) {
40
+ setRole(fallbackRole);
41
+ setLoading(false);
42
+ return;
43
+ }
44
+ let cancelled = false;
45
+ (async () => {
46
+ try {
47
+ const headers = {
48
+ Authorization: `Bearer ${token}`,
49
+ };
50
+ const res = await fetch(`${baseUrl}/api/sites/${encodeURIComponent(siteId)}/branches/${encodeURIComponent(branchId)}/auth/role`, { method: 'GET', headers });
51
+ if (cancelled)
52
+ return;
53
+ if (res.ok) {
54
+ const data = (await res.json());
55
+ if (data.roleName) {
56
+ setRole(mapCssRoleToContentRole(data.roleName));
57
+ setResolved(true);
58
+ }
59
+ else {
60
+ setRole(fallbackRole);
61
+ }
62
+ }
63
+ else {
64
+ setRole(fallbackRole);
65
+ }
66
+ }
67
+ catch {
68
+ if (!cancelled)
69
+ setRole(fallbackRole);
70
+ }
71
+ finally {
72
+ if (!cancelled)
73
+ setLoading(false);
74
+ }
75
+ })();
76
+ return () => {
77
+ cancelled = true;
78
+ };
79
+ }, [baseUrl, siteId, branchId, token, fallbackRole]);
80
+ return { role, loading, resolved };
81
+ }
82
+ export { mapCssRoleToContentRole };
83
+ //# sourceMappingURL=useResolveContentRole.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useResolveContentRole.js","sourceRoot":"","sources":["../../../../src/features/content-type-templates/permissions/useResolveContentRole.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAK5C,SAAS,uBAAuB,CAAC,OAAoB;IACnD,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ,CAAC;QACd,KAAK,WAAW,CAAC;QACjB;YACE,OAAO,eAAe,CAAC;IAC3B,CAAC;AACH,CAAC;AAgBD;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,OAAO,EACP,MAAM,EACN,QAAQ,EACR,KAAK,EACL,YAAY,GAAG,eAAe,GACD;IAC7B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAc,YAAY,CAAC,CAAC;IAC5D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEhD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YAClC,OAAO,CAAC,YAAY,CAAC,CAAC;YACtB,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,OAAO;QACT,CAAC;QAED,IAAI,SAAS,GAAG,KAAK,CAAC;QAEtB,CAAC,KAAK,IAAI,EAAE;YACV,IAAI,CAAC;gBACH,MAAM,OAAO,GAA2B;oBACtC,aAAa,EAAE,UAAU,KAAK,EAAE;iBACjC,CAAC;gBACF,MAAM,GAAG,GAAG,MAAM,KAAK,CACrB,GAAG,OAAO,cAAc,kBAAkB,CAAC,MAAM,CAAC,aAAa,kBAAkB,CAAC,QAAQ,CAAC,YAAY,EACvG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,CAC3B,CAAC;gBAEF,IAAI,SAAS;oBAAE,OAAO;gBAEtB,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;oBACX,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAA+B,CAAC;oBAC9D,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;wBAClB,OAAO,CAAC,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;wBAChD,WAAW,CAAC,IAAI,CAAC,CAAC;oBACpB,CAAC;yBAAM,CAAC;wBACN,OAAO,CAAC,YAAY,CAAC,CAAC;oBACxB,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,YAAY,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,IAAI,CAAC,SAAS;oBAAE,OAAO,CAAC,YAAY,CAAC,CAAC;YACxC,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,SAAS;oBAAE,UAAU,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;IAErD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACrC,CAAC;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Template Stores
3
+ *
4
+ * Store implementations for template persistence.
5
+ */
6
+ export type { TemplateStore } from './template-store.js';
7
+ export { createInMemoryTemplateStore } from './template-store.js';
8
+ export { createApiTemplateStore } from './template-store-api.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/content-type-templates/stores/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Template Stores
3
+ *
4
+ * Store implementations for template persistence.
5
+ */
6
+ export { createInMemoryTemplateStore } from './template-store.js';
7
+ export { createApiTemplateStore } from './template-store-api.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/features/content-type-templates/stores/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * API-Backed Template Store
3
+ *
4
+ * Production template store implementation using the backend API.
5
+ */
6
+ import type { P1Client } from '@pantheon-systems/css-client';
7
+ import type { TemplateStore } from './template-store.js';
8
+ /**
9
+ * Create a template store backed by the P1 API.
10
+ *
11
+ * @param client - P1Client instance
12
+ * @param siteId - Site ID
13
+ * @param branchId - Branch ID
14
+ * @returns TemplateStore instance
15
+ */
16
+ export declare function createApiTemplateStore(client: P1Client, siteId: string, branchId: string): TemplateStore;
17
+ //# sourceMappingURL=template-store-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-store-api.d.ts","sourceRoot":"","sources":["../../../../src/features/content-type-templates/stores/template-store-api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,aAAa,CAoDf"}