@powerhousedao/network-admin 0.0.25 → 0.0.26
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/dist/document-models/builder-profile/gen/actions.d.ts +4 -0
- package/dist/document-models/builder-profile/gen/actions.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/actions.js +1 -0
- package/dist/document-models/builder-profile/gen/builder/actions.d.ts +8 -0
- package/dist/document-models/builder-profile/gen/builder/actions.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/builder/actions.js +1 -0
- package/dist/document-models/builder-profile/gen/builder/creators.d.ts +4 -0
- package/dist/document-models/builder-profile/gen/builder/creators.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/builder/creators.js +3 -0
- package/dist/document-models/builder-profile/gen/builder/error.d.ts +2 -0
- package/dist/document-models/builder-profile/gen/builder/error.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/builder/error.js +1 -0
- package/dist/document-models/builder-profile/gen/builder/object.d.ts +7 -0
- package/dist/document-models/builder-profile/gen/builder/object.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/builder/object.js +7 -0
- package/dist/document-models/builder-profile/gen/builder/operations.d.ts +7 -0
- package/dist/document-models/builder-profile/gen/builder/operations.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/builder/operations.js +1 -0
- package/dist/document-models/builder-profile/gen/creators.d.ts +2 -0
- package/dist/document-models/builder-profile/gen/creators.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/creators.js +1 -0
- package/dist/document-models/builder-profile/gen/document-model.d.ts +3 -0
- package/dist/document-models/builder-profile/gen/document-model.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/document-model.js +48 -0
- package/dist/document-models/builder-profile/gen/index.d.ts +8 -0
- package/dist/document-models/builder-profile/gen/index.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/index.js +6 -0
- package/dist/document-models/builder-profile/gen/object.d.ts +15 -0
- package/dist/document-models/builder-profile/gen/object.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/object.js +25 -0
- package/dist/document-models/builder-profile/gen/ph-factories.d.ts +27 -0
- package/dist/document-models/builder-profile/gen/ph-factories.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/ph-factories.js +54 -0
- package/dist/document-models/builder-profile/gen/reducer.d.ts +5 -0
- package/dist/document-models/builder-profile/gen/reducer.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/reducer.js +20 -0
- package/dist/document-models/builder-profile/gen/schema/index.d.ts +3 -0
- package/dist/document-models/builder-profile/gen/schema/index.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/schema/index.js +2 -0
- package/dist/document-models/builder-profile/gen/schema/types.d.ts +151 -0
- package/dist/document-models/builder-profile/gen/schema/types.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/schema/types.js +1 -0
- package/dist/document-models/builder-profile/gen/schema/zod.d.ts +12 -0
- package/dist/document-models/builder-profile/gen/schema/zod.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/schema/zod.js +24 -0
- package/dist/document-models/builder-profile/gen/types.d.ts +10 -0
- package/dist/document-models/builder-profile/gen/types.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/types.js +1 -0
- package/dist/document-models/builder-profile/gen/utils.d.ts +22 -0
- package/dist/document-models/builder-profile/gen/utils.d.ts.map +1 -0
- package/dist/document-models/builder-profile/gen/utils.js +46 -0
- package/dist/document-models/builder-profile/index.d.ts +25 -0
- package/dist/document-models/builder-profile/index.d.ts.map +1 -0
- package/dist/document-models/builder-profile/index.js +21 -0
- package/dist/document-models/builder-profile/src/reducers/builder.d.ts +3 -0
- package/dist/document-models/builder-profile/src/reducers/builder.d.ts.map +1 -0
- package/dist/document-models/builder-profile/src/reducers/builder.js +9 -0
- package/dist/document-models/builder-profile/src/tests/builder.test.d.ts +2 -0
- package/dist/document-models/builder-profile/src/tests/builder.test.d.ts.map +1 -0
- package/dist/document-models/builder-profile/src/tests/builder.test.js +116 -0
- package/dist/document-models/builder-profile/src/tests/document-model.test.d.ts +6 -0
- package/dist/document-models/builder-profile/src/tests/document-model.test.d.ts.map +1 -0
- package/dist/document-models/builder-profile/src/tests/document-model.test.js +18 -0
- package/dist/document-models/builder-profile/src/utils.d.ts +2 -0
- package/dist/document-models/builder-profile/src/utils.d.ts.map +1 -0
- package/dist/document-models/builder-profile/src/utils.js +1 -0
- package/dist/document-models/index.d.ts.map +1 -1
- package/dist/editors/builder-profile/editor.d.ts +4 -0
- package/dist/editors/builder-profile/editor.d.ts.map +1 -0
- package/dist/editors/builder-profile/editor.js +101 -0
- package/dist/editors/builder-profile/index.d.ts +3 -0
- package/dist/editors/builder-profile/index.d.ts.map +1 -0
- package/dist/editors/builder-profile/index.js +11 -0
- package/dist/editors/hooks/useBuilderProfileDocument.d.ts +3 -0
- package/dist/editors/hooks/useBuilderProfileDocument.d.ts.map +1 -0
- package/dist/editors/hooks/useBuilderProfileDocument.js +8 -0
- package/dist/editors/index.d.ts.map +1 -1
- package/dist/powerhouse.manifest.json +7 -3
- package/dist/style.css +5371 -0
- package/dist/subgraphs/builder-profile/index.d.ts +11 -0
- package/dist/subgraphs/builder-profile/index.d.ts.map +1 -0
- package/dist/subgraphs/builder-profile/index.js +11 -0
- package/dist/subgraphs/builder-profile/resolvers.d.ts +3 -0
- package/dist/subgraphs/builder-profile/resolvers.d.ts.map +1 -0
- package/dist/subgraphs/builder-profile/resolvers.js +84 -0
- package/dist/subgraphs/builder-profile/schema.d.ts +3 -0
- package/dist/subgraphs/builder-profile/schema.d.ts.map +1 -0
- package/dist/subgraphs/builder-profile/schema.js +49 -0
- package/dist/subgraphs/index.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { baseCreateDocument, baseSaveToFile, baseSaveToFileHandle, baseLoadFromFile, baseLoadFromInput, defaultBaseState, generateId, } from "document-model";
|
|
2
|
+
import { reducer } from "./reducer.js";
|
|
3
|
+
export const initialGlobalState = {
|
|
4
|
+
id: null,
|
|
5
|
+
slug: null,
|
|
6
|
+
name: null,
|
|
7
|
+
icon: null,
|
|
8
|
+
description: null,
|
|
9
|
+
};
|
|
10
|
+
export const initialLocalState = {};
|
|
11
|
+
export const createState = (state) => {
|
|
12
|
+
return {
|
|
13
|
+
...defaultBaseState(),
|
|
14
|
+
global: { ...initialGlobalState, ...(state?.global ?? {}) },
|
|
15
|
+
local: { ...initialLocalState, ...(state?.local ?? {}) },
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const createDocument = (state) => {
|
|
19
|
+
const document = baseCreateDocument(createState, state);
|
|
20
|
+
document.header.documentType = "powerhouse/builder-profile";
|
|
21
|
+
// for backwards compatibility, but this is NOT a valid signed document id
|
|
22
|
+
document.header.id = generateId();
|
|
23
|
+
return document;
|
|
24
|
+
};
|
|
25
|
+
export const saveToFile = (document, path, name) => {
|
|
26
|
+
return baseSaveToFile(document, path, ".phdm", name);
|
|
27
|
+
};
|
|
28
|
+
export const saveToFileHandle = (document, input) => {
|
|
29
|
+
return baseSaveToFileHandle(document, input);
|
|
30
|
+
};
|
|
31
|
+
export const loadFromFile = (path) => {
|
|
32
|
+
return baseLoadFromFile(path, reducer);
|
|
33
|
+
};
|
|
34
|
+
export const loadFromInput = (input) => {
|
|
35
|
+
return baseLoadFromInput(input, reducer);
|
|
36
|
+
};
|
|
37
|
+
const utils = {
|
|
38
|
+
fileExtension: ".phdm",
|
|
39
|
+
createState,
|
|
40
|
+
createDocument,
|
|
41
|
+
saveToFile,
|
|
42
|
+
saveToFileHandle,
|
|
43
|
+
loadFromFile,
|
|
44
|
+
loadFromInput,
|
|
45
|
+
};
|
|
46
|
+
export default utils;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a scaffold file meant for customization.
|
|
3
|
+
* Delete the file and run the code generator again to have it reset
|
|
4
|
+
*/
|
|
5
|
+
import { type DocumentModelModule } from "document-model";
|
|
6
|
+
import { reducer } from "./gen/reducer.js";
|
|
7
|
+
import { documentModel } from "./gen/document-model.js";
|
|
8
|
+
import type { BuilderProfilePHState } from "./gen/ph-factories.js";
|
|
9
|
+
declare const utils: {
|
|
10
|
+
fileExtension: string;
|
|
11
|
+
createState: import("document-model").CreateState<BuilderProfilePHState>;
|
|
12
|
+
createDocument: import("document-model").CreateDocument<BuilderProfilePHState>;
|
|
13
|
+
saveToFile: (document: any, path: string, name?: string) => Promise<string>;
|
|
14
|
+
saveToFileHandle: (document: any, input: any) => Promise<void>;
|
|
15
|
+
loadFromFile: import("document-model").LoadFromFile<BuilderProfilePHState>;
|
|
16
|
+
loadFromInput: import("document-model").LoadFromInput<BuilderProfilePHState>;
|
|
17
|
+
};
|
|
18
|
+
declare const actions: {
|
|
19
|
+
updateProfile: (input: import("./gen/index.js").UpdateProfileInput) => import("./gen/index.js").UpdateProfileAction;
|
|
20
|
+
};
|
|
21
|
+
export declare const module: DocumentModelModule<BuilderProfilePHState>;
|
|
22
|
+
export { reducer, actions, utils, documentModel };
|
|
23
|
+
export * from "./gen/types.js";
|
|
24
|
+
export * from "./src/utils.js";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../document-models/builder-profile/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE,QAAA,MAAM,KAAK;;;;;;;;CAAkC,CAAC;AAC9C,QAAA,MAAM,OAAO;oBATb,kDACA;CAQ4D,CAAC;AAE7D,eAAO,MAAM,MAAM,EAAE,mBAAmB,CAAC,qBAAqB,CAK7D,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;AAElD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a scaffold file meant for customization.
|
|
3
|
+
* Delete the file and run the code generator again to have it reset
|
|
4
|
+
*/
|
|
5
|
+
import { actions as BaseActions, } from "document-model";
|
|
6
|
+
import { actions as BuilderProfileActions } from "./gen/index.js";
|
|
7
|
+
import { reducer } from "./gen/reducer.js";
|
|
8
|
+
import { documentModel } from "./gen/document-model.js";
|
|
9
|
+
import genUtils from "./gen/utils.js";
|
|
10
|
+
import * as customUtils from "./src/utils.js";
|
|
11
|
+
const utils = { ...genUtils, ...customUtils };
|
|
12
|
+
const actions = { ...BaseActions, ...BuilderProfileActions };
|
|
13
|
+
export const module = {
|
|
14
|
+
reducer,
|
|
15
|
+
actions,
|
|
16
|
+
utils,
|
|
17
|
+
documentModel,
|
|
18
|
+
};
|
|
19
|
+
export { reducer, actions, utils, documentModel };
|
|
20
|
+
export * from "./gen/types.js";
|
|
21
|
+
export * from "./src/utils.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../../../document-models/builder-profile/src/reducers/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAEvF,eAAO,MAAM,OAAO,EAAE,+BAQrB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const reducer = {
|
|
2
|
+
updateProfileOperation(state, action, dispatch) {
|
|
3
|
+
state.id = action.input.id ?? state.id;
|
|
4
|
+
state.slug = action.input.slug ?? state.slug;
|
|
5
|
+
state.name = action.input.name ?? state.name;
|
|
6
|
+
state.icon = action.input.icon ?? state.icon;
|
|
7
|
+
state.description = action.input.description ?? state.description;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.test.d.ts","sourceRoot":"","sources":["../../../../../document-models/builder-profile/src/tests/builder.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import utils from "../../gen/utils.js";
|
|
3
|
+
import { reducer } from "../../gen/reducer.js";
|
|
4
|
+
import * as creators from "../../gen/builder/creators.js";
|
|
5
|
+
import { z } from "../../gen/schema/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* BuilderProfile Document Model: Comprehensive Tests
|
|
8
|
+
* Focus: PHID and URL field validation, update, and expected behaviors
|
|
9
|
+
*/
|
|
10
|
+
const VALID_PHID = "phd:baefc2a4-f9a0-4950-8161-fd8d8cc7dea7";
|
|
11
|
+
const VALID_URL = "https://powerhouse.inc/icon.png";
|
|
12
|
+
const INVALID_PHID = "invalid:format:phid";
|
|
13
|
+
const INVALID_URL = "not-a-url";
|
|
14
|
+
describe("BuilderProfile Document Model", () => {
|
|
15
|
+
let document;
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
document = utils.createDocument();
|
|
18
|
+
});
|
|
19
|
+
it("should accept a valid PHID and URL in updateProfile", () => {
|
|
20
|
+
const input = {
|
|
21
|
+
id: VALID_PHID,
|
|
22
|
+
slug: "builder-slug",
|
|
23
|
+
name: "Builder Name",
|
|
24
|
+
icon: VALID_URL,
|
|
25
|
+
description: "A valid builder description"
|
|
26
|
+
};
|
|
27
|
+
// Should not throw during reducer/update
|
|
28
|
+
const updatedDocument = reducer(document, creators.updateProfile(input));
|
|
29
|
+
// Check operation appended with strict equality
|
|
30
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
31
|
+
const op = updatedDocument.operations.global[0];
|
|
32
|
+
expect(op.action.type).toBe("UPDATE_PROFILE");
|
|
33
|
+
expect(op.action.input).toStrictEqual(input);
|
|
34
|
+
// Ensure the PHID and URL fields persisted in state
|
|
35
|
+
expect(updatedDocument.state.global.id).toBe(VALID_PHID);
|
|
36
|
+
expect(updatedDocument.state.global.icon).toBe(VALID_URL);
|
|
37
|
+
});
|
|
38
|
+
it("should reject an invalid PHID using Zod validation", () => {
|
|
39
|
+
const input = {
|
|
40
|
+
id: INVALID_PHID,
|
|
41
|
+
slug: "builder-slug",
|
|
42
|
+
name: "Builder Name",
|
|
43
|
+
icon: VALID_URL,
|
|
44
|
+
description: "should fail phid"
|
|
45
|
+
};
|
|
46
|
+
// Zod parsing should throw
|
|
47
|
+
expect(() => z.UpdateProfileInputSchema().parse(input)).toThrow();
|
|
48
|
+
});
|
|
49
|
+
it("should reject an invalid URL using Zod validation", () => {
|
|
50
|
+
const input = {
|
|
51
|
+
id: VALID_PHID,
|
|
52
|
+
slug: "builder-slug",
|
|
53
|
+
name: "Builder Name",
|
|
54
|
+
icon: INVALID_URL,
|
|
55
|
+
description: "should fail url"
|
|
56
|
+
};
|
|
57
|
+
// Zod parsing should throw
|
|
58
|
+
expect(() => z.UpdateProfileInputSchema().parse(input)).toThrow();
|
|
59
|
+
});
|
|
60
|
+
it("should update only the URL and PHID fields if only they are provided", () => {
|
|
61
|
+
// The rest of the state is initialized to undefined by utils.createDocument()
|
|
62
|
+
// Set initial values
|
|
63
|
+
const initialInput = {
|
|
64
|
+
id: VALID_PHID,
|
|
65
|
+
slug: "slug-main",
|
|
66
|
+
name: "Initial Name",
|
|
67
|
+
icon: VALID_URL,
|
|
68
|
+
description: "Initial desc"
|
|
69
|
+
};
|
|
70
|
+
let currDoc = reducer(document, creators.updateProfile(initialInput));
|
|
71
|
+
// Now, update only id and icon
|
|
72
|
+
const updateInput = {
|
|
73
|
+
id: "phd:12345678-1111-2222-3333-abcdefabcdef:main:public",
|
|
74
|
+
icon: "https://updated-url.com/icon.svg"
|
|
75
|
+
};
|
|
76
|
+
currDoc = reducer(currDoc, creators.updateProfile(updateInput));
|
|
77
|
+
// id & icon changed, others remain
|
|
78
|
+
expect(currDoc.state.global.id).toBe(updateInput.id);
|
|
79
|
+
expect(currDoc.state.global.icon).toBe(updateInput.icon);
|
|
80
|
+
expect(currDoc.state.global.slug).toBe(initialInput.slug);
|
|
81
|
+
expect(currDoc.state.global.name).toBe(initialInput.name);
|
|
82
|
+
expect(currDoc.state.global.description).toBe(initialInput.description);
|
|
83
|
+
});
|
|
84
|
+
it("should allow updateProfile with partial inputs, always keeping PHID format valid", () => {
|
|
85
|
+
// Start with valid state
|
|
86
|
+
const initialState = {
|
|
87
|
+
id: VALID_PHID,
|
|
88
|
+
slug: "val-slug",
|
|
89
|
+
name: "val-name",
|
|
90
|
+
icon: VALID_URL,
|
|
91
|
+
description: "val desc"
|
|
92
|
+
};
|
|
93
|
+
let doc = reducer(document, creators.updateProfile(initialState));
|
|
94
|
+
// Now update only slug
|
|
95
|
+
const partialInput = {
|
|
96
|
+
slug: "new-slug"
|
|
97
|
+
};
|
|
98
|
+
doc = reducer(doc, creators.updateProfile(partialInput));
|
|
99
|
+
// id is preserved and still valid PHID
|
|
100
|
+
expect(doc.state.global.id).toBe(VALID_PHID);
|
|
101
|
+
// slug should update
|
|
102
|
+
expect(doc.state.global.slug).toBe("new-slug");
|
|
103
|
+
});
|
|
104
|
+
it("should throw if after a partial update the PHID is not valid", () => {
|
|
105
|
+
// Start with bad PHID in state
|
|
106
|
+
document.state.global.id = INVALID_PHID;
|
|
107
|
+
const input = {
|
|
108
|
+
slug: "doesnt-matter"
|
|
109
|
+
};
|
|
110
|
+
// Can't validate via reducer, so check with zod directly
|
|
111
|
+
expect(() => z.BuilderProfileStateSchema().parse({
|
|
112
|
+
...document.state,
|
|
113
|
+
...input
|
|
114
|
+
})).toThrow();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-model.test.d.ts","sourceRoot":"","sources":["../../../../../document-models/builder-profile/src/tests/document-model.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a scaffold file meant for customization:
|
|
3
|
+
* - change it by adding new tests or modifying the existing ones
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect } from "vitest";
|
|
6
|
+
import utils, { initialGlobalState, initialLocalState, } from "../../gen/utils.js";
|
|
7
|
+
describe("Builder Profile Document Model", () => {
|
|
8
|
+
it("should create a new Builder Profile document", () => {
|
|
9
|
+
const document = utils.createDocument();
|
|
10
|
+
expect(document).toBeDefined();
|
|
11
|
+
expect(document.header.documentType).toBe("powerhouse/builder-profile");
|
|
12
|
+
});
|
|
13
|
+
it("should create a new Builder Profile document with a valid initial state", () => {
|
|
14
|
+
const document = utils.createDocument();
|
|
15
|
+
expect(document.state.global).toStrictEqual(initialGlobalState);
|
|
16
|
+
expect(document.state.local).toStrictEqual(initialLocalState);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../document-models/builder-profile/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../document-models/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../document-models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAG,CAAC;AACX,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,MAAM,IAAI,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../editors/builder-profile/editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAWlD,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC;AAqMjC,MAAM,CAAC,OAAO,UAAU,MAAM,4CA4J7B"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { TextInput, Textarea, Icon, } from "@powerhousedao/document-engineering";
|
|
3
|
+
import { toast, ToastContainer } from "@powerhousedao/design-system";
|
|
4
|
+
import { actions } from "../../document-models/builder-profile/index.js";
|
|
5
|
+
import { useCallback, useState, useEffect } from "react";
|
|
6
|
+
import { useSelectedBuilderProfileDocument } from "../hooks/useBuilderProfileDocument.js";
|
|
7
|
+
// Image Modal Component
|
|
8
|
+
function ImageModal({ isOpen, onClose, imageUrl, imageAlt, }) {
|
|
9
|
+
const [imageLoaded, setImageLoaded] = useState(false);
|
|
10
|
+
const [imageDimensions, setImageDimensions] = useState({
|
|
11
|
+
width: 0,
|
|
12
|
+
height: 0,
|
|
13
|
+
});
|
|
14
|
+
if (!isOpen)
|
|
15
|
+
return null;
|
|
16
|
+
const handleImageLoad = (e) => {
|
|
17
|
+
const img = e.target;
|
|
18
|
+
setImageDimensions({ width: img.naturalWidth, height: img.naturalHeight });
|
|
19
|
+
setImageLoaded(true);
|
|
20
|
+
};
|
|
21
|
+
// Calculate modal size based on image dimensions with padding
|
|
22
|
+
const getModalSize = () => {
|
|
23
|
+
if (!imageLoaded)
|
|
24
|
+
return { width: "auto", height: "auto" };
|
|
25
|
+
const maxWidth = Math.min(imageDimensions.width + 100, window.innerWidth * 0.8);
|
|
26
|
+
const maxHeight = Math.min(imageDimensions.height + 100, window.innerHeight * 0.8);
|
|
27
|
+
return {
|
|
28
|
+
width: `${maxWidth}px`,
|
|
29
|
+
height: `${maxHeight}px`,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
return (_jsx("div", { className: "fixed inset-0 z-50 flex items-center justify-center backdrop-blur-sm", onClick: onClose, children: _jsxs("div", { className: "relative bg-gray-900 rounded-lg shadow-2xl border-2 border-gray-700", style: getModalSize(), children: [_jsx("button", { onClick: onClose, className: "absolute -top-3 -right-3 z-10 w-8 h-8 bg-gray-800 hover:bg-gray-900 rounded-full flex items-center justify-center text-white transition-all duration-200 shadow-lg", children: _jsx(Icon, { name: "ArrowLeft", size: 16 }) }), _jsx("div", { className: "w-full h-full flex items-center justify-center p-8", children: _jsx("img", { src: imageUrl, alt: imageAlt, className: `max-w-full max-h-full object-contain rounded-lg ${imageLoaded ? "opacity-100" : "opacity-0"} transition-opacity duration-200`, onClick: (e) => e.stopPropagation(), onLoad: handleImageLoad }) })] }) }));
|
|
33
|
+
}
|
|
34
|
+
// Image URL input component with preview
|
|
35
|
+
function ImageUrlInput({ label, value, onChange, placeholder, fileSize = "200KB", }) {
|
|
36
|
+
const [imageError, setImageError] = useState(false);
|
|
37
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
38
|
+
// Reset image error when value changes
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
setImageError(false);
|
|
41
|
+
}, [value]);
|
|
42
|
+
const handleImageClick = () => {
|
|
43
|
+
if (value &&
|
|
44
|
+
!imageError &&
|
|
45
|
+
(value.startsWith("http://") || value.startsWith("https://"))) {
|
|
46
|
+
setIsModalOpen(true);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "block text-sm font-medium text-gray-700", children: label }), _jsxs("div", { className: "border border-gray-300 rounded-lg p-4", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center space-x-3", children: [_jsx("div", { className: `flex-shrink-0 w-12 h-12 bg-gray-100 rounded border flex items-center justify-center overflow-hidden ${value &&
|
|
50
|
+
!imageError &&
|
|
51
|
+
(value.startsWith("http://") || value.startsWith("https://"))
|
|
52
|
+
? "cursor-pointer hover:opacity-80 transition-opacity duration-200"
|
|
53
|
+
: ""}`, onClick: handleImageClick, children: value &&
|
|
54
|
+
!imageError &&
|
|
55
|
+
(value.startsWith("http://") ||
|
|
56
|
+
value.startsWith("https://")) ? (_jsx("img", { src: value, alt: `${label} preview`, className: "w-full h-full object-cover", onError: () => setImageError(true), onLoad: () => setImageError(false) })) : (_jsx(Icon, { name: "Image", size: 24, className: "text-gray-400" })) }), _jsxs("div", { className: "flex-1", children: [_jsx("div", { className: "text-sm font-medium text-gray-900", children: value || placeholder || `${label.replace(":", "")}.jpg` }), _jsxs("div", { className: "text-xs text-gray-500", children: ["File Type: jpg | File Size: ", value ? fileSize : "0KB", imageError && value && (_jsx("div", { className: "text-red-500 mt-1", children: "\u26A0 Failed to load image" })), value &&
|
|
57
|
+
!imageError &&
|
|
58
|
+
(value.startsWith("http://") ||
|
|
59
|
+
value.startsWith("https://")) && (_jsx("div", { className: "text-blue-600 mt-1", children: "\uD83D\uDCA1 Click image to view full size" }))] })] })] }), _jsx("div", { className: "flex-shrink-0", children: _jsx("div", { className: "w-6 h-6 rounded-full bg-gray-200 flex items-center justify-center", children: _jsx(Icon, { name: "Image", size: 16, className: "text-gray-600" }) }) })] }), _jsx("div", { className: "mt-3", children: _jsx(TextInput, { className: "w-full", defaultValue: value || "", onBlur: (e) => {
|
|
60
|
+
if (e.target.value !== value) {
|
|
61
|
+
onChange(e.target.value);
|
|
62
|
+
}
|
|
63
|
+
}, placeholder: placeholder || "Enter image URL" }) })] })] }), _jsx(ImageModal, { isOpen: isModalOpen, onClose: () => setIsModalOpen(false), imageUrl: value, imageAlt: `${label} full size` })] }));
|
|
64
|
+
}
|
|
65
|
+
export default function Editor() {
|
|
66
|
+
// Getting dispatch from selected document
|
|
67
|
+
const [doc, dispatch] = useSelectedBuilderProfileDocument();
|
|
68
|
+
const state = doc.state.global;
|
|
69
|
+
// Handle field changes using the UPDATE_PROFILE operation
|
|
70
|
+
const handleFieldChange = useCallback((field, value) => {
|
|
71
|
+
if (!dispatch) {
|
|
72
|
+
console.error("Dispatch function not available");
|
|
73
|
+
toast(`Failed to update ${field} - no dispatch function`, {
|
|
74
|
+
type: "error",
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Create the update action with current state values and the new field value
|
|
79
|
+
const updateAction = actions.updateProfile({
|
|
80
|
+
id: state?.id || null,
|
|
81
|
+
slug: field === "slug" ? value : state?.slug || null,
|
|
82
|
+
name: field === "name" ? value : state?.name || null,
|
|
83
|
+
icon: field === "icon" ? value : state?.icon || null,
|
|
84
|
+
description: field === "description" ? value : state?.description || null,
|
|
85
|
+
});
|
|
86
|
+
dispatch(updateAction);
|
|
87
|
+
}, [dispatch, state]);
|
|
88
|
+
return (_jsx("div", { className: "w-full bg-gray-50 min-h-screen", children: _jsxs("div", { className: "p-6 max-w-4xl mx-auto", children: [_jsxs("div", { className: "bg-white rounded-lg p-6 mb-6 shadow-sm", children: [_jsx("h1", { className: "text-3xl font-bold text-gray-900 mb-2", children: "Builder Profile" }), _jsx("p", { className: "text-gray-600", children: "Create and manage your builder profile information" })] }), _jsx("div", { className: "bg-white rounded-lg p-6 shadow-sm", children: _jsxs("div", { className: "space-y-6", children: [_jsxs("div", { children: [_jsx("label", { className: "block text-sm font-medium text-gray-700 mb-2", children: "Builder Name:" }), _jsx(TextInput, { className: "w-full", defaultValue: state?.name || "", onBlur: (e) => {
|
|
89
|
+
if (e.target.value !== state?.name) {
|
|
90
|
+
handleFieldChange("name", e.target.value);
|
|
91
|
+
}
|
|
92
|
+
}, placeholder: "Enter your name" })] }), _jsxs("div", { children: [_jsx("label", { className: "block text-sm font-medium text-gray-700 mb-2", children: "Profile Slug:" }), _jsx(TextInput, { className: "w-full", defaultValue: state?.slug || "", onBlur: (e) => {
|
|
93
|
+
if (e.target.value !== state?.slug) {
|
|
94
|
+
handleFieldChange("slug", e.target.value);
|
|
95
|
+
}
|
|
96
|
+
}, placeholder: "your-profile-slug" }), _jsx("p", { className: "text-xs text-gray-500 mt-1", children: "Used for your profile URL (lowercase, no spaces)" })] }), _jsx(ImageUrlInput, { label: "Profile Icon:", value: state?.icon || "", onChange: (value) => handleFieldChange("icon", value), placeholder: "BuilderIcon.jpg", fileSize: "200KB" }), _jsxs("div", { children: [_jsx("label", { className: "block text-sm font-medium text-gray-700 mb-2", children: "Description:" }), _jsx(Textarea, { className: "w-full", defaultValue: state?.description || "", onBlur: (e) => {
|
|
97
|
+
if (e.target.value !== state?.description) {
|
|
98
|
+
handleFieldChange("description", e.target.value);
|
|
99
|
+
}
|
|
100
|
+
}, placeholder: "Tell us about yourself as a builder...", rows: 4 })] })] }) }), state && (state.name || state.icon || state.description) && (_jsxs("div", { className: "bg-white rounded-lg p-6 shadow-sm mt-6", children: [_jsx("h3", { className: "text-lg font-medium text-gray-900 mb-4", children: "Profile Preview" }), _jsx("div", { className: "border border-gray-200 rounded-lg p-4", children: _jsxs("div", { className: "flex items-start space-x-4", children: [_jsx("div", { className: "flex-shrink-0", children: state.icon ? (_jsx("img", { src: state.icon, alt: "Profile icon", className: "w-16 h-16 rounded-full object-cover border-2 border-gray-200" })) : (_jsx("div", { className: "w-16 h-16 rounded-full bg-gray-200 flex items-center justify-center", children: _jsx(Icon, { name: "Image", size: 24, className: "text-gray-400" }) })) }), _jsxs("div", { className: "flex-1", children: [_jsx("h4", { className: "text-lg font-semibold text-gray-900", children: state.name || "Unnamed Builder" }), state.slug && (_jsxs("p", { className: "text-sm text-gray-500 mb-2", children: ["@", state.slug] })), state.description && (_jsx("p", { className: "text-gray-700", children: state.description }))] })] }) })] })), _jsx(ToastContainer, {})] }) }));
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../editors/builder-profile/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,eAAO,MAAM,MAAM,EAAE,YASpB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Editor from "./editor.js";
|
|
2
|
+
export const module = {
|
|
3
|
+
Component: Editor,
|
|
4
|
+
documentTypes: ["powerhouse/builder-profile"],
|
|
5
|
+
config: {
|
|
6
|
+
id: "builder-profile-editor",
|
|
7
|
+
disableExternalControls: true,
|
|
8
|
+
documentToolbarEnabled: true,
|
|
9
|
+
showSwitchboardLink: true,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function useBuilderProfileDocument(documentId: string | null | undefined): never[] | [BuilderProfileDocument, import("@powerhousedao/reactor-browser").DocumentDispatch<BuilderProfileAction>];
|
|
2
|
+
export declare function useSelectedBuilderProfileDocument(): never[] | [BuilderProfileDocument, import("@powerhousedao/reactor-browser").DocumentDispatch<BuilderProfileAction>];
|
|
3
|
+
//# sourceMappingURL=useBuilderProfileDocument.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBuilderProfileDocument.d.ts","sourceRoot":"","sources":["../../../editors/hooks/useBuilderProfileDocument.ts"],"names":[],"mappings":"AASA,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,uHAMtC;AAED,wBAAgB,iCAAiC,wHAGhD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useDocumentOfType, useSelectedDocumentId, } from "@powerhousedao/reactor-browser";
|
|
2
|
+
export function useBuilderProfileDocument(documentId) {
|
|
3
|
+
return useDocumentOfType(documentId, "powerhouse/builder-profile");
|
|
4
|
+
}
|
|
5
|
+
export function useSelectedBuilderProfileDocument() {
|
|
6
|
+
const selectedDocumentId = useSelectedDocumentId();
|
|
7
|
+
return useBuilderProfileDocument(selectedDocumentId);
|
|
8
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../editors/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../editors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAG,CAAC;AACX,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,MAAM,IAAI,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,MAAM,IAAI,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "network-admin",
|
|
3
3
|
"description": "A place to handle all network related info",
|
|
4
|
-
"category": "
|
|
4
|
+
"category": "Project Management",
|
|
5
5
|
"publisher": {
|
|
6
|
-
"name": "
|
|
7
|
-
"url": ""
|
|
6
|
+
"name": "Powerhouse",
|
|
7
|
+
"url": "https://powerhouse.inc/"
|
|
8
8
|
},
|
|
9
9
|
"documentModels": [
|
|
10
10
|
{
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
{
|
|
23
23
|
"id": "powerhouse/network-profile",
|
|
24
24
|
"name": "Network Profile"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "powerhouse/builder-profile",
|
|
28
|
+
"name": "Builder Profile"
|
|
25
29
|
}
|
|
26
30
|
],
|
|
27
31
|
"editors": [
|