create-spfx-tailwind-app 1.0.16 โ 1.0.18
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/Template/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "template-spfx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"private": true,
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=22.14.0
|
|
6
|
+
"node": ">=22.14.0"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "heft test --clean --production && heft package-solution --production",
|
|
@@ -17,36 +17,36 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@fluentui/react": "^8.106.4",
|
|
20
|
-
"@microsoft/sp-component-base": "1.
|
|
21
|
-
"@microsoft/sp-core-library": "1.
|
|
22
|
-
"@microsoft/sp-lodash-subset": "1.
|
|
23
|
-
"@microsoft/sp-office-ui-fabric-core": "1.
|
|
24
|
-
"@microsoft/sp-property-pane": "1.
|
|
25
|
-
"@microsoft/sp-webpart-base": "1.
|
|
20
|
+
"@microsoft/sp-component-base": "1.24.0-beta.5",
|
|
21
|
+
"@microsoft/sp-core-library": "1.24.0-beta.5",
|
|
22
|
+
"@microsoft/sp-lodash-subset": "1.24.0-beta.5",
|
|
23
|
+
"@microsoft/sp-office-ui-fabric-core": "1.24.0-beta.5",
|
|
24
|
+
"@microsoft/sp-property-pane": "1.24.0-beta.5",
|
|
25
|
+
"@microsoft/sp-webpart-base": "1.24.0-beta.5",
|
|
26
26
|
"jquery": "^4.0.0",
|
|
27
|
-
"react": "
|
|
28
|
-
"react-dom": "
|
|
29
|
-
"tslib": "2.
|
|
27
|
+
"react": "^18.3.1",
|
|
28
|
+
"react-dom": "^18.3.1",
|
|
29
|
+
"tslib": "^2.6.2",
|
|
30
30
|
"uuid": "^14.0.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@microsoft/eslint-config-spfx": "1.
|
|
34
|
-
"@microsoft/eslint-plugin-spfx": "1.
|
|
35
|
-
"@microsoft/sp-module-interfaces": "1.
|
|
36
|
-
"@microsoft/spfx-heft-plugins": "1.
|
|
37
|
-
"@microsoft/spfx-web-build-rig": "1.
|
|
33
|
+
"@microsoft/eslint-config-spfx": "1.24.0-beta.5",
|
|
34
|
+
"@microsoft/eslint-plugin-spfx": "1.24.0-beta.5",
|
|
35
|
+
"@microsoft/sp-module-interfaces": "1.24.0-beta.5",
|
|
36
|
+
"@microsoft/spfx-heft-plugins": "1.24.0-beta.5",
|
|
37
|
+
"@microsoft/spfx-web-build-rig": "1.24.0-beta.5",
|
|
38
38
|
"@rushstack/eslint-config": "4.5.2",
|
|
39
39
|
"@rushstack/heft": "1.1.2",
|
|
40
40
|
"@types/heft-jest": "1.0.2",
|
|
41
41
|
"@types/jquery": "^4.0.0",
|
|
42
|
-
"@types/react": "
|
|
43
|
-
"@types/react-dom": "
|
|
42
|
+
"@types/react": "^18.3.18",
|
|
43
|
+
"@types/react-dom": "^18.3.5",
|
|
44
44
|
"@types/webpack-env": "~1.15.2",
|
|
45
45
|
"@typescript-eslint/parser": "8.46.2",
|
|
46
46
|
"autoprefixer": "^10.4.27",
|
|
47
47
|
"css-loader": "~7.1.2",
|
|
48
48
|
"eslint": "8.57.1",
|
|
49
|
-
"eslint-plugin-react-hooks": "
|
|
49
|
+
"eslint-plugin-react-hooks": "5.0.0",
|
|
50
50
|
"postcss": "^8.5.8",
|
|
51
51
|
"spfx-fast-serve": "^4.0.2",
|
|
52
52
|
"tailwindcss": "^3.4.19",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"@rushstack/heft": "1.1.2"
|
|
57
57
|
},
|
|
58
58
|
"resolutions": {
|
|
59
|
-
"@types/react": "
|
|
59
|
+
"@types/react": "^18.3.18",
|
|
60
|
+
"@types/react-dom": "^18.3.5"
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -1,130 +1,176 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import * as ReactDom from
|
|
3
|
-
import { Version } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as ReactDom from "react-dom/client";
|
|
3
|
+
import { Version } from "@microsoft/sp-core-library";
|
|
4
4
|
import {
|
|
5
5
|
type IPropertyPaneConfiguration,
|
|
6
|
-
PropertyPaneTextField
|
|
7
|
-
} from
|
|
8
|
-
import { BaseClientSideWebPart } from
|
|
9
|
-
import { IReadonlyTheme } from
|
|
6
|
+
PropertyPaneTextField,
|
|
7
|
+
} from "@microsoft/sp-property-pane";
|
|
8
|
+
import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
|
|
9
|
+
import { IReadonlyTheme } from "@microsoft/sp-component-base";
|
|
10
10
|
import { SPHttpClient, SPHttpClientResponse } from "@microsoft/sp-http";
|
|
11
11
|
import "../../tailwind.generated.css";
|
|
12
|
-
import * as strings from
|
|
12
|
+
import * as strings from "TemplateSpfxWebPartStrings";
|
|
13
13
|
import __PROJECT_NAME__ from "./components/__PROJECT_NAME__";
|
|
14
|
-
import { I__PROJECT_NAME__Props } from
|
|
14
|
+
import { I__PROJECT_NAME__Props } from "./components/I__PROJECT_NAME__Props";
|
|
15
15
|
import $ from "jquery";
|
|
16
|
+
|
|
16
17
|
export interface I__PROJECT_NAME__WebPartProps {
|
|
17
18
|
description: string;
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
interface ISharePointUserGroup {
|
|
22
|
+
Id: number;
|
|
23
|
+
Title: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface IUserData {
|
|
27
|
+
id: number;
|
|
28
|
+
title: string;
|
|
29
|
+
email: string;
|
|
30
|
+
groups: ISharePointUserGroup[];
|
|
31
|
+
}
|
|
32
|
+
|
|
20
33
|
export default class __PROJECT_NAME__WebPart extends BaseClientSideWebPart<I__PROJECT_NAME__WebPartProps> {
|
|
21
34
|
private _isDarkTheme: boolean = false;
|
|
22
|
-
private
|
|
23
|
-
|
|
35
|
+
private _root: ReactDom.Root | null = null;
|
|
36
|
+
private _userData: IUserData = {
|
|
37
|
+
id: -1,
|
|
38
|
+
title: "",
|
|
39
|
+
email: "",
|
|
40
|
+
groups: [],
|
|
41
|
+
};
|
|
42
|
+
private _domObserver: MutationObserver | null = null;
|
|
43
|
+
private _injectedStyleElement: HTMLStyleElement | null = null;
|
|
44
|
+
|
|
45
|
+
public async getCurrentUserGroups(
|
|
46
|
+
requester: SPHttpClient,
|
|
47
|
+
siteUrl: string,
|
|
48
|
+
): Promise<IUserData> {
|
|
24
49
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"odata-version": "",
|
|
33
|
-
},
|
|
50
|
+
const response: SPHttpClientResponse = await requester.get(
|
|
51
|
+
`${siteUrl}/_api/web/currentuser/?$select=Title,Email,LoginName,Id&$expand=groups`,
|
|
52
|
+
SPHttpClient.configurations.v1,
|
|
53
|
+
{
|
|
54
|
+
headers: {
|
|
55
|
+
Accept: "application/json;odata=verbose",
|
|
56
|
+
"odata-version": "",
|
|
34
57
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error(`HTTP ${response.status} - ${response.statusText}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const json = await response.json();
|
|
66
|
+
const user = json?.d;
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
id: user?.Id ?? -1,
|
|
70
|
+
title: user?.Title ?? "",
|
|
71
|
+
email: this.context.pageContext.user.email || user?.Email || "",
|
|
72
|
+
groups: user?.Groups?.results ?? [],
|
|
73
|
+
};
|
|
74
|
+
} catch (error: unknown) {
|
|
75
|
+
console.error(
|
|
76
|
+
"[SPFx] Error fetching current user groups:",
|
|
77
|
+
error instanceof Error ? error.message : error,
|
|
45
78
|
);
|
|
46
|
-
|
|
79
|
+
return {
|
|
80
|
+
id: -1,
|
|
81
|
+
title: "",
|
|
82
|
+
email: this.context.pageContext.user.email || "",
|
|
83
|
+
groups: [],
|
|
84
|
+
};
|
|
47
85
|
}
|
|
48
86
|
}
|
|
49
87
|
|
|
50
|
-
|
|
51
|
-
|
|
88
|
+
protected async onInit(): Promise<void> {
|
|
89
|
+
await super.onInit();
|
|
90
|
+
|
|
91
|
+
// 1. Fetch user data before rendering component
|
|
92
|
+
this._userData = await this.getCurrentUserGroups(
|
|
52
93
|
this.context.spHttpClient,
|
|
53
94
|
this.context.pageContext.web.absoluteUrl,
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
newgroups: currentUser?.d?.Groups?.results || [],
|
|
65
|
-
newcurrentUserEmail: this.context.pageContext.user.email,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
ReactDom.render(element, this.domElement);
|
|
69
|
-
});
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
document.title = "MIS Repository";
|
|
98
|
+
$("body").addClass("ms-backgroundImage");
|
|
99
|
+
|
|
100
|
+
// 2. Inject CSS rules once
|
|
101
|
+
this._injectHideStyles();
|
|
102
|
+
|
|
103
|
+
// 3. Setup dynamic chrome hiding using MutationObserver
|
|
104
|
+
this._setupDomObserver();
|
|
70
105
|
}
|
|
71
106
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
107
|
+
public render(): void {
|
|
108
|
+
const element: React.ReactElement<I__PROJECT_NAME__Props> =
|
|
109
|
+
React.createElement(__PROJECT_NAME__, {
|
|
110
|
+
newcontext: this.context,
|
|
111
|
+
newsiteUrl: this.context.pageContext.web.absoluteUrl,
|
|
112
|
+
newlistName: "",
|
|
113
|
+
newspHttpClient: this.context.spHttpClient,
|
|
114
|
+
newrelativeUrl: this.context.pageContext.web.serverRelativeUrl,
|
|
115
|
+
newcurrentUserId: this._userData.id,
|
|
116
|
+
newcurrentUserName: this._userData.title,
|
|
117
|
+
newgroups: this._userData.groups,
|
|
118
|
+
newcurrentUserEmail: this._userData.email,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// React 18 createRoot
|
|
122
|
+
if (!this._root) {
|
|
123
|
+
this._root = ReactDom.createRoot(this.domElement);
|
|
124
|
+
}
|
|
125
|
+
this._root.render(element);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private _injectHideStyles(): void {
|
|
129
|
+
const selectors = [
|
|
130
|
+
"#spLeftNav",
|
|
131
|
+
"#SuiteNavWrapper",
|
|
132
|
+
"#CommentsWrapper",
|
|
133
|
+
"#sp-appBar",
|
|
134
|
+
".headerRow-107",
|
|
135
|
+
".commandBarButtonHeightAndColor",
|
|
136
|
+
".fui-Toolbar",
|
|
137
|
+
".simpleFooterContainer-196",
|
|
138
|
+
".p_i-Dej_1x34n",
|
|
139
|
+
'div[data-automation-id="pageHeader"]',
|
|
140
|
+
'div[data-automation-id="SiteHeader"]',
|
|
141
|
+
'div[data-automation-id="MegaFooter"]',
|
|
142
|
+
'div[data-automation-id="gradientBox"]',
|
|
143
|
+
'div[data-automation-id="LeftNavGroups"]',
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
this._injectedStyleElement = document.createElement("style");
|
|
147
|
+
this._injectedStyleElement.innerHTML = `
|
|
148
|
+
${selectors.join(", ")} {
|
|
96
149
|
display: none !important;
|
|
97
150
|
}
|
|
98
151
|
`;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// Delay + repeat (IMPORTANT for SPFx dynamic DOM)
|
|
102
|
-
const hideElements = () => {
|
|
103
|
-
$("div[data-automation-id='pageHeader']").hide();
|
|
104
|
-
$("div[data-automation-id='SiteHeader']").hide();
|
|
105
|
-
$("div[data-automation-id='SimpleFooter']").parent().hide();
|
|
106
|
-
$("div[data-automation-id='SiteHeaderOverlay']").parent().hide();
|
|
107
|
-
$("div[data-automation-id='MegaFooter']").hide();
|
|
108
|
-
$("div[data-automation-id='gradientBox']").parent().hide();
|
|
109
|
-
$("div[data-automation-id='LeftNavGroups']").parent().hide();
|
|
110
|
-
|
|
111
|
-
$("#spLeftNav").hide();
|
|
112
|
-
$("#SuiteNavWrapper").hide();
|
|
113
|
-
$("#CommentsWrapper").hide();
|
|
114
|
-
$("#sp-appBar").hide();
|
|
115
|
-
|
|
116
|
-
$(".headerRow-107").hide();
|
|
117
|
-
$(".commandBarButtonHeightAndColor").hide();
|
|
118
|
-
$(".fui-Toolbar").hide();
|
|
119
|
-
};
|
|
152
|
+
document.head.appendChild(this._injectedStyleElement);
|
|
153
|
+
}
|
|
120
154
|
|
|
121
|
-
|
|
122
|
-
|
|
155
|
+
private _setupDomObserver(): void {
|
|
156
|
+
const hideExtraNodes = (): void => {
|
|
157
|
+
$(
|
|
158
|
+
"div[data-automation-id='SimpleFooter'], div[data-automation-id='SiteHeaderOverlay'], div[data-automation-id='gradientBox'], div[data-automation-id='LeftNavGroups']",
|
|
159
|
+
)
|
|
160
|
+
.parent()
|
|
161
|
+
.hide();
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
hideExtraNodes();
|
|
123
165
|
|
|
124
|
-
|
|
125
|
-
|
|
166
|
+
// Observe changes instead of polling via setInterval
|
|
167
|
+
this._domObserver = new MutationObserver(() => {
|
|
168
|
+
hideExtraNodes();
|
|
169
|
+
});
|
|
126
170
|
|
|
127
|
-
|
|
171
|
+
this._domObserver.observe(document.body, {
|
|
172
|
+
childList: true,
|
|
173
|
+
subtree: true,
|
|
128
174
|
});
|
|
129
175
|
}
|
|
130
176
|
|
|
@@ -150,7 +196,25 @@ export default class __PROJECT_NAME__WebPart extends BaseClientSideWebPart<I__PR
|
|
|
150
196
|
}
|
|
151
197
|
|
|
152
198
|
protected onDispose(): void {
|
|
153
|
-
|
|
199
|
+
// 1. Disconnect DOM observer
|
|
200
|
+
if (this._domObserver) {
|
|
201
|
+
this._domObserver.disconnect();
|
|
202
|
+
this._domObserver = null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 2. Remove dynamically injected CSS tag
|
|
206
|
+
if (this._injectedStyleElement && this._injectedStyleElement.parentNode) {
|
|
207
|
+
this._injectedStyleElement.parentNode.removeChild(
|
|
208
|
+
this._injectedStyleElement,
|
|
209
|
+
);
|
|
210
|
+
this._injectedStyleElement = null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// 3. Unmount React 18 component tree
|
|
214
|
+
if (this._root) {
|
|
215
|
+
this._root.unmount();
|
|
216
|
+
this._root = null;
|
|
217
|
+
}
|
|
154
218
|
}
|
|
155
219
|
|
|
156
220
|
protected get dataVersion(): Version {
|
package/index.js
CHANGED
|
@@ -8,11 +8,6 @@ const ora = require("ora");
|
|
|
8
8
|
const inquirer = require("inquirer");
|
|
9
9
|
const figlet = require("figlet");
|
|
10
10
|
const gradient = require("gradient-string").default;
|
|
11
|
-
const setupPath = path.join(targetDir, "setup.js");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// ๐จ Banner
|
|
15
|
-
|
|
16
11
|
|
|
17
12
|
console.log(
|
|
18
13
|
gradient.instagram(figlet.textSync("SPFx CLI", { horizontalLayout: "full" })),
|
|
@@ -21,11 +16,8 @@ console.log(
|
|
|
21
16
|
async function run() {
|
|
22
17
|
try {
|
|
23
18
|
const args = process.argv.slice(2);
|
|
24
|
-
|
|
25
|
-
// ๐น detect flags
|
|
26
19
|
const noInstallFlag = args.includes("--no-install");
|
|
27
20
|
|
|
28
|
-
// ๐น get project name
|
|
29
21
|
let projectName = args.find((arg) => !arg.startsWith("--"));
|
|
30
22
|
|
|
31
23
|
if (!projectName) {
|
|
@@ -47,6 +39,7 @@ async function run() {
|
|
|
47
39
|
|
|
48
40
|
const templateDir = path.join(__dirname, "Template");
|
|
49
41
|
const targetDir = path.join(process.cwd(), projectName);
|
|
42
|
+
const setupPath = path.join(targetDir, "setup.js");
|
|
50
43
|
|
|
51
44
|
console.log(chalk.cyan("\n๐ Creating your SPFx project...\n"));
|
|
52
45
|
|
|
@@ -55,33 +48,39 @@ async function run() {
|
|
|
55
48
|
// ๐ Copy template
|
|
56
49
|
fs.cpSync(templateDir, targetDir, { recursive: true });
|
|
57
50
|
|
|
58
|
-
spinner.text = "
|
|
51
|
+
spinner.text = "Running setup...";
|
|
59
52
|
|
|
60
|
-
// โ Run setup
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
// โ Run setup.js if exists
|
|
54
|
+
if (fs.existsSync(setupPath)) {
|
|
55
|
+
execSync(`node setup.js "${projectName}"`, {
|
|
56
|
+
cwd: targetDir,
|
|
57
|
+
stdio: "inherit",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
65
60
|
|
|
66
|
-
spinner.
|
|
61
|
+
spinner.text = "Cleaning up...";
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
// ๐งน Remove setup.js after execution
|
|
64
|
+
try {
|
|
65
|
+
if (fs.existsSync(setupPath)) {
|
|
66
|
+
fs.unlinkSync(setupPath);
|
|
67
|
+
// optional log
|
|
68
|
+
// console.log(chalk.gray("๐งน setup.js removed"));
|
|
69
|
+
}
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.log(chalk.yellow("โ ๏ธ Could not remove setup.js"));
|
|
72
|
+
}
|
|
76
73
|
|
|
77
|
-
|
|
74
|
+
spinner.succeed(chalk.green("โ Project setup complete"));
|
|
75
|
+
|
|
76
|
+
// ๐ detect Tailwind
|
|
78
77
|
let hasTailwind = false;
|
|
79
78
|
try {
|
|
80
79
|
const pkg = require(path.join(targetDir, "package.json"));
|
|
81
80
|
hasTailwind = !!pkg.scripts?.["build:tailwind"];
|
|
82
81
|
} catch {}
|
|
83
82
|
|
|
84
|
-
// โ Ask install
|
|
83
|
+
// โ Ask install
|
|
85
84
|
let install = true;
|
|
86
85
|
|
|
87
86
|
if (noInstallFlag) {
|
|
@@ -114,7 +113,7 @@ async function run() {
|
|
|
114
113
|
}
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
// ๐
|
|
116
|
+
// ๐ Done
|
|
118
117
|
console.log("\n" + chalk.bold.green("๐ Project created successfully!\n"));
|
|
119
118
|
|
|
120
119
|
console.log(chalk.yellow("๐ Next steps:"));
|
|
@@ -138,7 +137,6 @@ async function run() {
|
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
console.log("\n" + chalk.gray("Happy coding ๐\n"));
|
|
141
|
-
|
|
142
140
|
} catch (err) {
|
|
143
141
|
console.log(chalk.red("\nโ Something went wrong\n"));
|
|
144
142
|
console.error(err);
|