@elementor/editor-current-user 0.1.0

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.
@@ -0,0 +1,22 @@
1
+
2
+ > @elementor/editor-current-user@0.1.0 build
3
+ > tsup --config=../../tsup.build.ts
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: ../../../tsconfig.json
7
+ CLI tsup v8.4.0
8
+ CLI Using tsup config: /home/runner/work/elementor-packages/elementor-packages/tsup.build.ts
9
+ CLI Target: esnext
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ CJS dist/index.js 2.53 KB
14
+ CJS dist/index.js.map 3.00 KB
15
+ CJS ⚡️ Build success in 49ms
16
+ ESM dist/index.mjs 1.39 KB
17
+ ESM dist/index.mjs.map 2.80 KB
18
+ ESM ⚡️ Build success in 51ms
19
+ DTS Build start
20
+ DTS ⚡️ Build success in 9572ms
21
+ DTS dist/index.d.mts 476.00 B
22
+ DTS dist/index.d.ts 476.00 B
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @elementor/editor-current-user
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c0e30dd: Add editor current user api
@@ -0,0 +1,14 @@
1
+ import * as _tanstack_react_query from '@tanstack/react-query';
2
+ import * as axios from 'axios';
3
+
4
+ type User = {
5
+ suppressedMessages: string[];
6
+ };
7
+
8
+ declare const useCurrentUser: () => _tanstack_react_query.UseQueryResult<User, Error>;
9
+
10
+ declare const useUpdateCurrentUser: () => _tanstack_react_query.UseMutationResult<axios.AxiosResponse<{
11
+ elementor_introduction: Record<string, boolean>;
12
+ }, any>, Error, User, unknown>;
13
+
14
+ export { useCurrentUser, useUpdateCurrentUser };
@@ -0,0 +1,14 @@
1
+ import * as _tanstack_react_query from '@tanstack/react-query';
2
+ import * as axios from 'axios';
3
+
4
+ type User = {
5
+ suppressedMessages: string[];
6
+ };
7
+
8
+ declare const useCurrentUser: () => _tanstack_react_query.UseQueryResult<User, Error>;
9
+
10
+ declare const useUpdateCurrentUser: () => _tanstack_react_query.UseMutationResult<axios.AxiosResponse<{
11
+ elementor_introduction: Record<string, boolean>;
12
+ }, any>, Error, User, unknown>;
13
+
14
+ export { useCurrentUser, useUpdateCurrentUser };
package/dist/index.js ADDED
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ useCurrentUser: () => useCurrentUser,
24
+ useUpdateCurrentUser: () => useUpdateCurrentUser
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/use-current-user.ts
29
+ var import_query = require("@elementor/query");
30
+
31
+ // src/api.ts
32
+ var import_http = require("@elementor/http");
33
+ var RESOURCE_URL = "/users/me";
34
+ var apiClient = {
35
+ get: () => (0, import_http.httpService)().get("wp/v2" + RESOURCE_URL).then((res) => {
36
+ return responseToUser(res.data);
37
+ }),
38
+ update: (data) => (0, import_http.httpService)().patch("wp/v2" + RESOURCE_URL, userToRequest(data))
39
+ };
40
+ var responseToUser = (response) => {
41
+ return {
42
+ suppressedMessages: Object.entries(response.elementor_introduction).filter(([, value]) => value).map(([message]) => message)
43
+ };
44
+ };
45
+ var userToRequest = (user) => {
46
+ return {
47
+ elementor_introduction: user.suppressedMessages.reduce(
48
+ (acc, message) => {
49
+ acc[message] = true;
50
+ return acc;
51
+ },
52
+ {}
53
+ )
54
+ };
55
+ };
56
+
57
+ // src/use-current-user.ts
58
+ var EDITOR_CURRENT_USER_QUERY_KEY = "editor-current-user";
59
+ var useCurrentUser = () => {
60
+ return (0, import_query.useQuery)({
61
+ queryKey: [EDITOR_CURRENT_USER_QUERY_KEY],
62
+ queryFn: apiClient.get
63
+ });
64
+ };
65
+
66
+ // src/use-update-current-user.ts
67
+ var import_query2 = require("@elementor/query");
68
+ var useUpdateCurrentUser = () => {
69
+ const queryClient = (0, import_query2.useQueryClient)();
70
+ return (0, import_query2.useMutation)({
71
+ mutationFn: apiClient.update,
72
+ onSuccess: () => queryClient.invalidateQueries({ queryKey: [EDITOR_CURRENT_USER_QUERY_KEY] })
73
+ });
74
+ };
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ useCurrentUser,
78
+ useUpdateCurrentUser
79
+ });
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/use-current-user.ts","../src/api.ts","../src/use-update-current-user.ts"],"sourcesContent":["export { useCurrentUser } from './use-current-user';\nexport { useUpdateCurrentUser } from './use-update-current-user';\n","import { useQuery } from '@elementor/query';\n\nimport { apiClient } from './api';\n\nexport const EDITOR_CURRENT_USER_QUERY_KEY = 'editor-current-user';\n\nexport const useCurrentUser = () => {\n\treturn useQuery( {\n\t\tqueryKey: [ EDITOR_CURRENT_USER_QUERY_KEY ],\n\t\tqueryFn: apiClient.get,\n\t} );\n};\n","import { httpService } from '@elementor/http';\n\nimport { type User } from './types';\n\nconst RESOURCE_URL = '/users/me';\n\ntype UserModel = {\n\telementor_introduction: Record< string, boolean >;\n};\n\nexport const apiClient = {\n\tget: () =>\n\t\thttpService()\n\t\t\t.get< UserModel >( 'wp/v2' + RESOURCE_URL )\n\t\t\t.then( ( res ) => {\n\t\t\t\treturn responseToUser( res.data );\n\t\t\t} ),\n\tupdate: ( data: User ) => httpService().patch< UserModel >( 'wp/v2' + RESOURCE_URL, userToRequest( data ) ),\n};\n\nconst responseToUser = ( response: UserModel ): User => {\n\treturn {\n\t\tsuppressedMessages: Object.entries( response.elementor_introduction )\n\t\t\t.filter( ( [ , value ] ) => value )\n\t\t\t.map( ( [ message ] ) => message ),\n\t};\n};\n\nconst userToRequest = ( user: User ): UserModel => {\n\treturn {\n\t\telementor_introduction: user.suppressedMessages.reduce(\n\t\t\t( acc, message ) => {\n\t\t\t\tacc[ message ] = true;\n\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{} as Record< string, boolean >\n\t\t),\n\t};\n};\n","import { useMutation, useQueryClient } from '@elementor/query';\n\nimport { apiClient } from './api';\nimport { EDITOR_CURRENT_USER_QUERY_KEY } from './use-current-user';\n\nexport const useUpdateCurrentUser = () => {\n\tconst queryClient = useQueryClient();\n\n\treturn useMutation( {\n\t\tmutationFn: apiClient.update,\n\t\tonSuccess: () => queryClient.invalidateQueries( { queryKey: [ EDITOR_CURRENT_USER_QUERY_KEY ] } ),\n\t} );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyB;;;ACAzB,kBAA4B;AAI5B,IAAM,eAAe;AAMd,IAAM,YAAY;AAAA,EACxB,KAAK,UACJ,yBAAY,EACV,IAAkB,UAAU,YAAa,EACzC,KAAM,CAAE,QAAS;AACjB,WAAO,eAAgB,IAAI,IAAK;AAAA,EACjC,CAAE;AAAA,EACJ,QAAQ,CAAE,aAAgB,yBAAY,EAAE,MAAoB,UAAU,cAAc,cAAe,IAAK,CAAE;AAC3G;AAEA,IAAM,iBAAiB,CAAE,aAA+B;AACvD,SAAO;AAAA,IACN,oBAAoB,OAAO,QAAS,SAAS,sBAAuB,EAClE,OAAQ,CAAE,CAAE,EAAE,KAAM,MAAO,KAAM,EACjC,IAAK,CAAE,CAAE,OAAQ,MAAO,OAAQ;AAAA,EACnC;AACD;AAEA,IAAM,gBAAgB,CAAE,SAA2B;AAClD,SAAO;AAAA,IACN,wBAAwB,KAAK,mBAAmB;AAAA,MAC/C,CAAE,KAAK,YAAa;AACnB,YAAK,OAAQ,IAAI;AAEjB,eAAO;AAAA,MACR;AAAA,MACA,CAAC;AAAA,IACF;AAAA,EACD;AACD;;;ADnCO,IAAM,gCAAgC;AAEtC,IAAM,iBAAiB,MAAM;AACnC,aAAO,uBAAU;AAAA,IAChB,UAAU,CAAE,6BAA8B;AAAA,IAC1C,SAAS,UAAU;AAAA,EACpB,CAAE;AACH;;;AEXA,IAAAA,gBAA4C;AAKrC,IAAM,uBAAuB,MAAM;AACzC,QAAM,kBAAc,8BAAe;AAEnC,aAAO,2BAAa;AAAA,IACnB,YAAY,UAAU;AAAA,IACtB,WAAW,MAAM,YAAY,kBAAmB,EAAE,UAAU,CAAE,6BAA8B,EAAE,CAAE;AAAA,EACjG,CAAE;AACH;","names":["import_query"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,52 @@
1
+ // src/use-current-user.ts
2
+ import { useQuery } from "@elementor/query";
3
+
4
+ // src/api.ts
5
+ import { httpService } from "@elementor/http";
6
+ var RESOURCE_URL = "/users/me";
7
+ var apiClient = {
8
+ get: () => httpService().get("wp/v2" + RESOURCE_URL).then((res) => {
9
+ return responseToUser(res.data);
10
+ }),
11
+ update: (data) => httpService().patch("wp/v2" + RESOURCE_URL, userToRequest(data))
12
+ };
13
+ var responseToUser = (response) => {
14
+ return {
15
+ suppressedMessages: Object.entries(response.elementor_introduction).filter(([, value]) => value).map(([message]) => message)
16
+ };
17
+ };
18
+ var userToRequest = (user) => {
19
+ return {
20
+ elementor_introduction: user.suppressedMessages.reduce(
21
+ (acc, message) => {
22
+ acc[message] = true;
23
+ return acc;
24
+ },
25
+ {}
26
+ )
27
+ };
28
+ };
29
+
30
+ // src/use-current-user.ts
31
+ var EDITOR_CURRENT_USER_QUERY_KEY = "editor-current-user";
32
+ var useCurrentUser = () => {
33
+ return useQuery({
34
+ queryKey: [EDITOR_CURRENT_USER_QUERY_KEY],
35
+ queryFn: apiClient.get
36
+ });
37
+ };
38
+
39
+ // src/use-update-current-user.ts
40
+ import { useMutation, useQueryClient } from "@elementor/query";
41
+ var useUpdateCurrentUser = () => {
42
+ const queryClient = useQueryClient();
43
+ return useMutation({
44
+ mutationFn: apiClient.update,
45
+ onSuccess: () => queryClient.invalidateQueries({ queryKey: [EDITOR_CURRENT_USER_QUERY_KEY] })
46
+ });
47
+ };
48
+ export {
49
+ useCurrentUser,
50
+ useUpdateCurrentUser
51
+ };
52
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/use-current-user.ts","../src/api.ts","../src/use-update-current-user.ts"],"sourcesContent":["import { useQuery } from '@elementor/query';\n\nimport { apiClient } from './api';\n\nexport const EDITOR_CURRENT_USER_QUERY_KEY = 'editor-current-user';\n\nexport const useCurrentUser = () => {\n\treturn useQuery( {\n\t\tqueryKey: [ EDITOR_CURRENT_USER_QUERY_KEY ],\n\t\tqueryFn: apiClient.get,\n\t} );\n};\n","import { httpService } from '@elementor/http';\n\nimport { type User } from './types';\n\nconst RESOURCE_URL = '/users/me';\n\ntype UserModel = {\n\telementor_introduction: Record< string, boolean >;\n};\n\nexport const apiClient = {\n\tget: () =>\n\t\thttpService()\n\t\t\t.get< UserModel >( 'wp/v2' + RESOURCE_URL )\n\t\t\t.then( ( res ) => {\n\t\t\t\treturn responseToUser( res.data );\n\t\t\t} ),\n\tupdate: ( data: User ) => httpService().patch< UserModel >( 'wp/v2' + RESOURCE_URL, userToRequest( data ) ),\n};\n\nconst responseToUser = ( response: UserModel ): User => {\n\treturn {\n\t\tsuppressedMessages: Object.entries( response.elementor_introduction )\n\t\t\t.filter( ( [ , value ] ) => value )\n\t\t\t.map( ( [ message ] ) => message ),\n\t};\n};\n\nconst userToRequest = ( user: User ): UserModel => {\n\treturn {\n\t\telementor_introduction: user.suppressedMessages.reduce(\n\t\t\t( acc, message ) => {\n\t\t\t\tacc[ message ] = true;\n\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{} as Record< string, boolean >\n\t\t),\n\t};\n};\n","import { useMutation, useQueryClient } from '@elementor/query';\n\nimport { apiClient } from './api';\nimport { EDITOR_CURRENT_USER_QUERY_KEY } from './use-current-user';\n\nexport const useUpdateCurrentUser = () => {\n\tconst queryClient = useQueryClient();\n\n\treturn useMutation( {\n\t\tmutationFn: apiClient.update,\n\t\tonSuccess: () => queryClient.invalidateQueries( { queryKey: [ EDITOR_CURRENT_USER_QUERY_KEY ] } ),\n\t} );\n};\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,SAAS,mBAAmB;AAI5B,IAAM,eAAe;AAMd,IAAM,YAAY;AAAA,EACxB,KAAK,MACJ,YAAY,EACV,IAAkB,UAAU,YAAa,EACzC,KAAM,CAAE,QAAS;AACjB,WAAO,eAAgB,IAAI,IAAK;AAAA,EACjC,CAAE;AAAA,EACJ,QAAQ,CAAE,SAAgB,YAAY,EAAE,MAAoB,UAAU,cAAc,cAAe,IAAK,CAAE;AAC3G;AAEA,IAAM,iBAAiB,CAAE,aAA+B;AACvD,SAAO;AAAA,IACN,oBAAoB,OAAO,QAAS,SAAS,sBAAuB,EAClE,OAAQ,CAAE,CAAE,EAAE,KAAM,MAAO,KAAM,EACjC,IAAK,CAAE,CAAE,OAAQ,MAAO,OAAQ;AAAA,EACnC;AACD;AAEA,IAAM,gBAAgB,CAAE,SAA2B;AAClD,SAAO;AAAA,IACN,wBAAwB,KAAK,mBAAmB;AAAA,MAC/C,CAAE,KAAK,YAAa;AACnB,YAAK,OAAQ,IAAI;AAEjB,eAAO;AAAA,MACR;AAAA,MACA,CAAC;AAAA,IACF;AAAA,EACD;AACD;;;ADnCO,IAAM,gCAAgC;AAEtC,IAAM,iBAAiB,MAAM;AACnC,SAAO,SAAU;AAAA,IAChB,UAAU,CAAE,6BAA8B;AAAA,IAC1C,SAAS,UAAU;AAAA,EACpB,CAAE;AACH;;;AEXA,SAAS,aAAa,sBAAsB;AAKrC,IAAM,uBAAuB,MAAM;AACzC,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAa;AAAA,IACnB,YAAY,UAAU;AAAA,IACtB,WAAW,MAAM,YAAY,kBAAmB,EAAE,UAAU,CAAE,6BAA8B,EAAE,CAAE;AAAA,EACjG,CAAE;AACH;","names":[]}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@elementor/editor-current-user",
3
+ "description": "Elementor Editor Current User",
4
+ "version": "0.1.0",
5
+ "private": false,
6
+ "author": "Elementor Team",
7
+ "homepage": "https://elementor.com/",
8
+ "license": "GPL-3.0-or-later",
9
+ "main": "dist/index.js",
10
+ "module": "dist/index.mjs",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.js"
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/elementor/elementor-packages.git",
23
+ "directory": "packages/libs/editor-current-user"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/elementor/elementor-packages/issues"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "build": "tsup --config=../../tsup.build.ts",
33
+ "dev": "tsup --config=../../tsup.dev.ts"
34
+ },
35
+ "peerDependencies": {
36
+ "react": "^18.3.1"
37
+ },
38
+ "dependencies": {
39
+ "@elementor/http": "0.1.3",
40
+ "@elementor/query": "0.2.4"
41
+ },
42
+ "devDependencies": {
43
+ "tsup": "^8.3.5"
44
+ }
45
+ }
package/src/api.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { httpService } from '@elementor/http';
2
+
3
+ import { type User } from './types';
4
+
5
+ const RESOURCE_URL = '/users/me';
6
+
7
+ type UserModel = {
8
+ elementor_introduction: Record< string, boolean >;
9
+ };
10
+
11
+ export const apiClient = {
12
+ get: () =>
13
+ httpService()
14
+ .get< UserModel >( 'wp/v2' + RESOURCE_URL )
15
+ .then( ( res ) => {
16
+ return responseToUser( res.data );
17
+ } ),
18
+ update: ( data: User ) => httpService().patch< UserModel >( 'wp/v2' + RESOURCE_URL, userToRequest( data ) ),
19
+ };
20
+
21
+ const responseToUser = ( response: UserModel ): User => {
22
+ return {
23
+ suppressedMessages: Object.entries( response.elementor_introduction )
24
+ .filter( ( [ , value ] ) => value )
25
+ .map( ( [ message ] ) => message ),
26
+ };
27
+ };
28
+
29
+ const userToRequest = ( user: User ): UserModel => {
30
+ return {
31
+ elementor_introduction: user.suppressedMessages.reduce(
32
+ ( acc, message ) => {
33
+ acc[ message ] = true;
34
+
35
+ return acc;
36
+ },
37
+ {} as Record< string, boolean >
38
+ ),
39
+ };
40
+ };
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { useCurrentUser } from './use-current-user';
2
+ export { useUpdateCurrentUser } from './use-update-current-user';
package/src/types.ts ADDED
@@ -0,0 +1,3 @@
1
+ export type User = {
2
+ suppressedMessages: string[];
3
+ };
@@ -0,0 +1,12 @@
1
+ import { useQuery } from '@elementor/query';
2
+
3
+ import { apiClient } from './api';
4
+
5
+ export const EDITOR_CURRENT_USER_QUERY_KEY = 'editor-current-user';
6
+
7
+ export const useCurrentUser = () => {
8
+ return useQuery( {
9
+ queryKey: [ EDITOR_CURRENT_USER_QUERY_KEY ],
10
+ queryFn: apiClient.get,
11
+ } );
12
+ };
@@ -0,0 +1,13 @@
1
+ import { useMutation, useQueryClient } from '@elementor/query';
2
+
3
+ import { apiClient } from './api';
4
+ import { EDITOR_CURRENT_USER_QUERY_KEY } from './use-current-user';
5
+
6
+ export const useUpdateCurrentUser = () => {
7
+ const queryClient = useQueryClient();
8
+
9
+ return useMutation( {
10
+ mutationFn: apiClient.update,
11
+ onSuccess: () => queryClient.invalidateQueries( { queryKey: [ EDITOR_CURRENT_USER_QUERY_KEY ] } ),
12
+ } );
13
+ };