@momentumcms/admin 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Momentum CMS Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # admin
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test admin` to execute the unit tests.
@@ -0,0 +1,90 @@
1
+ import * as i0 from '@angular/core';
2
+ import { inject, viewChild, computed, ChangeDetectionStrategy, Component } from '@angular/core';
3
+ import { ActivatedRoute } from '@angular/router';
4
+ import { humanizeFieldName } from '@momentumcms/core';
5
+ import { g as getGlobalsFromRouteData, E as EntityFormWidget } from './momentumcms-admin-momentumcms-admin-z82jXEsP.mjs';
6
+
7
+ /**
8
+ * Global Edit Page
9
+ *
10
+ * Renders the EntityFormWidget in global (singleton) mode for editing a global document.
11
+ * The global config is converted to a CollectionConfig shape and passed with isGlobal=true.
12
+ */
13
+ class GlobalEditPage {
14
+ route = inject(ActivatedRoute);
15
+ entityFormRef = viewChild('entityForm', ...(ngDevMode ? [{ debugName: "entityFormRef" }] : []));
16
+ globalSlug = computed(() => {
17
+ return this.route.snapshot.paramMap.get('slug') ?? '';
18
+ }, ...(ngDevMode ? [{ debugName: "globalSlug" }] : []));
19
+ globalConfig = computed(() => {
20
+ const slug = this.globalSlug();
21
+ const globals = getGlobalsFromRouteData(this.route.parent?.snapshot.data);
22
+ return globals.find((g) => g.slug === slug);
23
+ }, ...(ngDevMode ? [{ debugName: "globalConfig" }] : []));
24
+ /** Convert GlobalConfig to CollectionConfig shape for EntityFormWidget */
25
+ collectionConfig = computed(() => {
26
+ const global = this.globalConfig();
27
+ if (!global)
28
+ return undefined;
29
+ return {
30
+ slug: global.slug,
31
+ fields: global.fields,
32
+ labels: {
33
+ singular: global.label ?? humanizeFieldName(global.slug),
34
+ plural: global.label ?? humanizeFieldName(global.slug),
35
+ },
36
+ admin: global.admin,
37
+ access: global.access
38
+ ? { read: global.access.read, update: global.access.update }
39
+ : undefined,
40
+ hooks: global.hooks,
41
+ versions: global.versions,
42
+ };
43
+ }, ...(ngDevMode ? [{ debugName: "collectionConfig" }] : []));
44
+ hasUnsavedChanges() {
45
+ return this.entityFormRef()?.isDirty() ?? false;
46
+ }
47
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: GlobalEditPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
48
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.2", type: GlobalEditPage, isStandalone: true, selector: "mcms-global-edit", host: { classAttribute: "block" }, viewQueries: [{ propertyName: "entityFormRef", first: true, predicate: ["entityForm"], descendants: true, isSignal: true }], ngImport: i0, template: `
49
+ @if (collectionConfig(); as col) {
50
+ <mcms-entity-form
51
+ #entityForm
52
+ [collection]="col"
53
+ [mode]="'edit'"
54
+ [basePath]="'/admin/globals'"
55
+ [showBreadcrumbs]="true"
56
+ [isGlobal]="true"
57
+ [globalSlug]="globalSlug()"
58
+ />
59
+ } @else {
60
+ <div class="p-12 text-center text-muted-foreground">Global not found</div>
61
+ }
62
+ `, isInline: true, dependencies: [{ kind: "component", type: EntityFormWidget, selector: "mcms-entity-form", inputs: ["collection", "entityId", "mode", "basePath", "showBreadcrumbs", "suppressNavigation", "isGlobal", "globalSlug"], outputs: ["saved", "cancelled", "saveError", "modeChange", "draftSaved"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
63
+ }
64
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: GlobalEditPage, decorators: [{
65
+ type: Component,
66
+ args: [{
67
+ selector: 'mcms-global-edit',
68
+ imports: [EntityFormWidget],
69
+ changeDetection: ChangeDetectionStrategy.OnPush,
70
+ host: { class: 'block' },
71
+ template: `
72
+ @if (collectionConfig(); as col) {
73
+ <mcms-entity-form
74
+ #entityForm
75
+ [collection]="col"
76
+ [mode]="'edit'"
77
+ [basePath]="'/admin/globals'"
78
+ [showBreadcrumbs]="true"
79
+ [isGlobal]="true"
80
+ [globalSlug]="globalSlug()"
81
+ />
82
+ } @else {
83
+ <div class="p-12 text-center text-muted-foreground">Global not found</div>
84
+ }
85
+ `,
86
+ }]
87
+ }], propDecorators: { entityFormRef: [{ type: i0.ViewChild, args: ['entityForm', { isSignal: true }] }] } });
88
+
89
+ export { GlobalEditPage };
90
+ //# sourceMappingURL=momentumcms-admin-global-edit.page-DFDV-uh3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"momentumcms-admin-global-edit.page-DFDV-uh3.mjs","sources":["../../../../libs/admin/src/lib/pages/global-edit/global-edit.page.ts"],"sourcesContent":["import { Component, ChangeDetectionStrategy, inject, computed, viewChild } from '@angular/core';\nimport { ActivatedRoute } from '@angular/router';\nimport type { CollectionConfig, GlobalConfig } from '@momentumcms/core';\nimport { humanizeFieldName } from '@momentumcms/core';\nimport { getGlobalsFromRouteData } from '../../utils/route-data';\nimport { EntityFormWidget } from '../../widgets/entity-form/entity-form.component';\nimport type { HasUnsavedChanges } from '../../guards/unsaved-changes.guard';\n\n/**\n * Global Edit Page\n *\n * Renders the EntityFormWidget in global (singleton) mode for editing a global document.\n * The global config is converted to a CollectionConfig shape and passed with isGlobal=true.\n */\n@Component({\n\tselector: 'mcms-global-edit',\n\timports: [EntityFormWidget],\n\tchangeDetection: ChangeDetectionStrategy.OnPush,\n\thost: { class: 'block' },\n\ttemplate: `\n\t\t@if (collectionConfig(); as col) {\n\t\t\t<mcms-entity-form\n\t\t\t\t#entityForm\n\t\t\t\t[collection]=\"col\"\n\t\t\t\t[mode]=\"'edit'\"\n\t\t\t\t[basePath]=\"'/admin/globals'\"\n\t\t\t\t[showBreadcrumbs]=\"true\"\n\t\t\t\t[isGlobal]=\"true\"\n\t\t\t\t[globalSlug]=\"globalSlug()\"\n\t\t\t/>\n\t\t} @else {\n\t\t\t<div class=\"p-12 text-center text-muted-foreground\">Global not found</div>\n\t\t}\n\t`,\n})\nexport class GlobalEditPage implements HasUnsavedChanges {\n\tprivate readonly route = inject(ActivatedRoute);\n\n\tprivate readonly entityFormRef = viewChild<EntityFormWidget>('entityForm');\n\n\treadonly globalSlug = computed((): string => {\n\t\treturn this.route.snapshot.paramMap.get('slug') ?? '';\n\t});\n\n\treadonly globalConfig = computed((): GlobalConfig | undefined => {\n\t\tconst slug = this.globalSlug();\n\t\tconst globals = getGlobalsFromRouteData(this.route.parent?.snapshot.data);\n\t\treturn globals.find((g) => g.slug === slug);\n\t});\n\n\t/** Convert GlobalConfig to CollectionConfig shape for EntityFormWidget */\n\treadonly collectionConfig = computed((): CollectionConfig | undefined => {\n\t\tconst global = this.globalConfig();\n\t\tif (!global) return undefined;\n\n\t\treturn {\n\t\t\tslug: global.slug,\n\t\t\tfields: global.fields,\n\t\t\tlabels: {\n\t\t\t\tsingular: global.label ?? humanizeFieldName(global.slug),\n\t\t\t\tplural: global.label ?? humanizeFieldName(global.slug),\n\t\t\t},\n\t\t\tadmin: global.admin,\n\t\t\taccess: global.access\n\t\t\t\t? { read: global.access.read, update: global.access.update }\n\t\t\t\t: undefined,\n\t\t\thooks: global.hooks,\n\t\t\tversions: global.versions,\n\t\t};\n\t});\n\n\thasUnsavedChanges(): boolean {\n\t\treturn this.entityFormRef()?.isDirty() ?? false;\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAQA;;;;;AAKG;MAsBU,cAAc,CAAA;AACT,IAAA,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC;AAE9B,IAAA,aAAa,GAAG,SAAS,CAAmB,YAAY,yDAAC;AAEjE,IAAA,UAAU,GAAG,QAAQ,CAAC,MAAa;AAC3C,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE;AACtD,IAAA,CAAC,sDAAC;AAEO,IAAA,YAAY,GAAG,QAAQ,CAAC,MAA+B;AAC/D,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE;AAC9B,QAAA,MAAM,OAAO,GAAG,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC;AACzE,QAAA,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;AAC5C,IAAA,CAAC,wDAAC;;AAGO,IAAA,gBAAgB,GAAG,QAAQ,CAAC,MAAmC;AACvE,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE;AAClC,QAAA,IAAI,CAAC,MAAM;AAAE,YAAA,OAAO,SAAS;QAE7B,OAAO;YACN,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,MAAM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