@elementor/editor-agents 4.3.0-1031
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/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +139 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +100 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +53 -0
- package/src/components/agents-settings-tab.tsx +50 -0
- package/src/index.ts +2 -0
- package/src/init.ts +22 -0
- package/src/llms-settings.ts +59 -0
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AGENTS_SITE_SETTINGS_TAB_ID: () => AGENTS_SITE_SETTINGS_TAB_ID,
|
|
34
|
+
AgentsSettingsTab: () => AgentsSettingsTab,
|
|
35
|
+
init: () => init
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/init.ts
|
|
40
|
+
var import_editor_site_settings = require("@elementor/editor-site-settings");
|
|
41
|
+
|
|
42
|
+
// src/components/agents-settings-tab.tsx
|
|
43
|
+
var React = __toESM(require("react"));
|
|
44
|
+
var import_react = require("react");
|
|
45
|
+
var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
46
|
+
var import_ui = require("@elementor/ui");
|
|
47
|
+
var import_i18n = require("@wordpress/i18n");
|
|
48
|
+
|
|
49
|
+
// src/llms-settings.ts
|
|
50
|
+
var import_editor_documents = require("@elementor/editor-documents");
|
|
51
|
+
var AGENTS_SETTINGS_KEY = "agents";
|
|
52
|
+
var LLMS_SETTINGS_KEY = "llms";
|
|
53
|
+
function getSiteSettingsBag() {
|
|
54
|
+
const settings = (0, import_editor_documents.getV1CurrentDocument)()?.container?.settings;
|
|
55
|
+
return settings ? settings : null;
|
|
56
|
+
}
|
|
57
|
+
function readAgentsSettings(settings) {
|
|
58
|
+
const agents = settings?.get(AGENTS_SETTINGS_KEY);
|
|
59
|
+
return agents && typeof agents === "object" ? { ...agents } : {};
|
|
60
|
+
}
|
|
61
|
+
function omitLlms(agents) {
|
|
62
|
+
return Object.fromEntries(Object.entries(agents).filter(([key]) => key !== LLMS_SETTINGS_KEY));
|
|
63
|
+
}
|
|
64
|
+
function isEmpty(agents) {
|
|
65
|
+
return 0 === Object.keys(agents).length;
|
|
66
|
+
}
|
|
67
|
+
function readLlmsContent() {
|
|
68
|
+
const llms = readAgentsSettings(getSiteSettingsBag())[LLMS_SETTINGS_KEY];
|
|
69
|
+
return typeof llms === "string" ? llms : "";
|
|
70
|
+
}
|
|
71
|
+
function writeLlmsContent(content) {
|
|
72
|
+
const settings = getSiteSettingsBag();
|
|
73
|
+
if (!settings) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const agents = readAgentsSettings(settings);
|
|
77
|
+
if ("" === content) {
|
|
78
|
+
const remainingAgents = omitLlms(agents);
|
|
79
|
+
settings.set(AGENTS_SETTINGS_KEY, isEmpty(remainingAgents) ? void 0 : remainingAgents);
|
|
80
|
+
} else {
|
|
81
|
+
settings.set(AGENTS_SETTINGS_KEY, { ...agents, [LLMS_SETTINGS_KEY]: content });
|
|
82
|
+
}
|
|
83
|
+
(0, import_editor_documents.setDocumentModifiedStatus)(true);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/components/agents-settings-tab.tsx
|
|
88
|
+
var TAB_ID = "settings-agents";
|
|
89
|
+
var TAB_ROUTE = `panel/global/${TAB_ID}`;
|
|
90
|
+
function AgentsSettingsTab() {
|
|
91
|
+
const [value, setValue] = (0, import_react.useState)(readLlmsContent);
|
|
92
|
+
const [isSettingsAvailable, setIsSettingsAvailable] = (0, import_react.useState)(() => null !== getSiteSettingsBag());
|
|
93
|
+
(0, import_editor_v1_adapters.__privateUseListenTo)([(0, import_editor_v1_adapters.routeOpenEvent)(TAB_ROUTE)], () => {
|
|
94
|
+
setIsSettingsAvailable(null !== getSiteSettingsBag());
|
|
95
|
+
setValue(readLlmsContent());
|
|
96
|
+
});
|
|
97
|
+
const handleChange = (0, import_react.useCallback)((event) => {
|
|
98
|
+
const nextValue = event.target.value;
|
|
99
|
+
setValue(nextValue);
|
|
100
|
+
writeLlmsContent(nextValue);
|
|
101
|
+
}, []);
|
|
102
|
+
return /* @__PURE__ */ React.createElement(import_ui.Box, { sx: { p: 2 } }, /* @__PURE__ */ React.createElement(import_ui.Stack, { spacing: 1.5 }, /* @__PURE__ */ React.createElement(import_ui.Typography, { variant: "subtitle2" }, (0, import_i18n.__)("Agents", "elementor")), /* @__PURE__ */ React.createElement(
|
|
103
|
+
import_ui.TextField,
|
|
104
|
+
{
|
|
105
|
+
label: (0, import_i18n.__)("llms.txt", "elementor"),
|
|
106
|
+
value,
|
|
107
|
+
onChange: handleChange,
|
|
108
|
+
multiline: true,
|
|
109
|
+
minRows: 12,
|
|
110
|
+
fullWidth: true,
|
|
111
|
+
disabled: !isSettingsAvailable,
|
|
112
|
+
helperText: isSettingsAvailable ? (0, import_i18n.__)("Content served at /llms.txt when saved. Leave empty to disable.", "elementor") : (0, import_i18n.__)("Kit settings are unavailable. Reopen Site Settings and try again.", "elementor")
|
|
113
|
+
}
|
|
114
|
+
)));
|
|
115
|
+
}
|
|
116
|
+
var AGENTS_SITE_SETTINGS_TAB_ID = TAB_ID;
|
|
117
|
+
|
|
118
|
+
// src/init.ts
|
|
119
|
+
var EXPERIMENT_NAME = "agents_llms_txt";
|
|
120
|
+
function isAgentsExperimentActive() {
|
|
121
|
+
const features = window.elementorCommon?.config?.experimentalFeatures ?? {};
|
|
122
|
+
return Boolean(features[EXPERIMENT_NAME]);
|
|
123
|
+
}
|
|
124
|
+
function init() {
|
|
125
|
+
if (!isAgentsExperimentActive()) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
(0, import_editor_site_settings.injectSiteSettingsTab)({
|
|
129
|
+
id: AGENTS_SITE_SETTINGS_TAB_ID,
|
|
130
|
+
component: AgentsSettingsTab
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
AGENTS_SITE_SETTINGS_TAB_ID,
|
|
136
|
+
AgentsSettingsTab,
|
|
137
|
+
init
|
|
138
|
+
});
|
|
139
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/init.ts","../src/components/agents-settings-tab.tsx","../src/llms-settings.ts"],"sourcesContent":["export { init } from './init';\nexport { AGENTS_SITE_SETTINGS_TAB_ID, AgentsSettingsTab } from './components/agents-settings-tab';\n","import { injectSiteSettingsTab } from '@elementor/editor-site-settings';\n\nimport { AGENTS_SITE_SETTINGS_TAB_ID, AgentsSettingsTab } from './components/agents-settings-tab';\n\nconst EXPERIMENT_NAME = 'agents_llms_txt';\n\nfunction isAgentsExperimentActive(): boolean {\n\tconst features = window.elementorCommon?.config?.experimentalFeatures ?? {};\n\n\treturn Boolean( features[ EXPERIMENT_NAME ] );\n}\n\nexport function init() {\n\tif ( ! isAgentsExperimentActive() ) {\n\t\treturn;\n\t}\n\n\tinjectSiteSettingsTab( {\n\t\tid: AGENTS_SITE_SETTINGS_TAB_ID,\n\t\tcomponent: AgentsSettingsTab,\n\t} );\n}\n","import * as React from 'react';\nimport { useCallback, useState } from 'react';\nimport { __privateUseListenTo as useListenTo, routeOpenEvent } from '@elementor/editor-v1-adapters';\nimport { Box, Stack, TextField, Typography } from '@elementor/ui';\nimport { __ } from '@wordpress/i18n';\n\nimport { getSiteSettingsBag, readLlmsContent, writeLlmsContent } from '../llms-settings';\n\nconst TAB_ID = 'settings-agents';\nconst TAB_ROUTE = `panel/global/${ TAB_ID }`;\n\nexport function AgentsSettingsTab() {\n\tconst [ value, setValue ] = useState( readLlmsContent );\n\tconst [ isSettingsAvailable, setIsSettingsAvailable ] = useState( () => null !== getSiteSettingsBag() );\n\n\tuseListenTo( [ routeOpenEvent( TAB_ROUTE ) ], () => {\n\t\tsetIsSettingsAvailable( null !== getSiteSettingsBag() );\n\t\tsetValue( readLlmsContent() );\n\t} );\n\n\tconst handleChange = useCallback( ( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\tconst nextValue = event.target.value;\n\t\tsetValue( nextValue );\n\t\twriteLlmsContent( nextValue );\n\t}, [] );\n\n\treturn (\n\t\t<Box sx={ { p: 2 } }>\n\t\t\t<Stack spacing={ 1.5 }>\n\t\t\t\t<Typography variant=\"subtitle2\">{ __( 'Agents', 'elementor' ) }</Typography>\n\t\t\t\t<TextField\n\t\t\t\t\tlabel={ __( 'llms.txt', 'elementor' ) }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ handleChange }\n\t\t\t\t\tmultiline\n\t\t\t\t\tminRows={ 12 }\n\t\t\t\t\tfullWidth\n\t\t\t\t\tdisabled={ ! isSettingsAvailable }\n\t\t\t\t\thelperText={\n\t\t\t\t\t\tisSettingsAvailable\n\t\t\t\t\t\t\t? __( 'Content served at /llms.txt when saved. Leave empty to disable.', 'elementor' )\n\t\t\t\t\t\t\t: __( 'Kit settings are unavailable. Reopen Site Settings and try again.', 'elementor' )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</Stack>\n\t\t</Box>\n\t);\n}\n\nexport const AGENTS_SITE_SETTINGS_TAB_ID = TAB_ID;\n","import { getV1CurrentDocument, setDocumentModifiedStatus } from '@elementor/editor-documents';\n\nexport const AGENTS_SETTINGS_KEY = 'agents';\nexport const LLMS_SETTINGS_KEY = 'llms';\n\ntype AgentsSettings = Record< string, unknown >;\n\ntype SettingsBag = {\n\tget: ( key: string ) => unknown;\n\tset: ( key: string, value: unknown ) => void;\n};\n\nexport function getSiteSettingsBag(): SettingsBag | null {\n\tconst settings = getV1CurrentDocument()?.container?.settings;\n\n\treturn settings ? ( settings as SettingsBag ) : null;\n}\n\nfunction readAgentsSettings( settings: SettingsBag | null ): AgentsSettings {\n\tconst agents = settings?.get( AGENTS_SETTINGS_KEY );\n\n\treturn agents && typeof agents === 'object' ? { ...( agents as AgentsSettings ) } : {};\n}\n\nfunction omitLlms( agents: AgentsSettings ): AgentsSettings {\n\treturn Object.fromEntries( Object.entries( agents ).filter( ( [ key ] ) => key !== LLMS_SETTINGS_KEY ) );\n}\n\nfunction isEmpty( agents: AgentsSettings ): boolean {\n\treturn 0 === Object.keys( agents ).length;\n}\n\nexport function readLlmsContent(): string {\n\tconst llms = readAgentsSettings( getSiteSettingsBag() )[ LLMS_SETTINGS_KEY ];\n\n\treturn typeof llms === 'string' ? llms : '';\n}\n\nexport function writeLlmsContent( content: string ): boolean {\n\tconst settings = getSiteSettingsBag();\n\n\tif ( ! settings ) {\n\t\treturn false;\n\t}\n\n\tconst agents = readAgentsSettings( settings );\n\n\tif ( '' === content ) {\n\t\tconst remainingAgents = omitLlms( agents );\n\n\t\tsettings.set( AGENTS_SETTINGS_KEY, isEmpty( remainingAgents ) ? undefined : remainingAgents );\n\t} else {\n\t\tsettings.set( AGENTS_SETTINGS_KEY, { ...agents, [ LLMS_SETTINGS_KEY ]: content } );\n\t}\n\n\tsetDocumentModifiedStatus( true );\n\n\treturn true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kCAAsC;;;ACAtC,YAAuB;AACvB,mBAAsC;AACtC,gCAAoE;AACpE,gBAAkD;AAClD,kBAAmB;;;ACJnB,8BAAgE;AAEzD,IAAM,sBAAsB;AAC5B,IAAM,oBAAoB;AAS1B,SAAS,qBAAyC;AACxD,QAAM,eAAW,8CAAqB,GAAG,WAAW;AAEpD,SAAO,WAAa,WAA4B;AACjD;AAEA,SAAS,mBAAoB,UAA+C;AAC3E,QAAM,SAAS,UAAU,IAAK,mBAAoB;AAElD,SAAO,UAAU,OAAO,WAAW,WAAW,EAAE,GAAK,OAA2B,IAAI,CAAC;AACtF;AAEA,SAAS,SAAU,QAAyC;AAC3D,SAAO,OAAO,YAAa,OAAO,QAAS,MAAO,EAAE,OAAQ,CAAE,CAAE,GAAI,MAAO,QAAQ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AAG,GAC/D;AAAA,IAAC;AAAA;AAAA,MACA,WAAQ,gBAAI,YAAY,WAAY;AAAA,MACpC;AAAA,MACA,UAAW;AAAA,MACX,WAAS;AAAA,MACT,SAAU;AAAA,MACV,WAAS;AAAA,MACT,UAAW,CAAE;AAAA,MACb,YACC,0BACG,gBAAI,mEAAmE,WAAY,QACnF,gBAAI,qEAAqE,WAAY;AAAA;AAAA,EAE1F,CACD,CACD;AAEF;AAEO,IAAM,8BAA8B;;;AD7C3C,IAAM,kBAAkB;AAExB,SAAS,2BAAoC;AAC5C,QAAM,WAAW,OAAO,iBAAiB,QAAQ,wBAAwB,CAAC;AAE1E,SAAO,QAAS,SAAU,eAAgB,CAAE;AAC7C;AAEO,SAAS,OAAO;AACtB,MAAK,CAAE,yBAAyB,GAAI;AACnC;AAAA,EACD;AAEA,yDAAuB;AAAA,IACtB,IAAI;AAAA,IACJ,WAAW;AAAA,EACZ,CAAE;AACH;","names":["useListenTo"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/init.ts
|
|
2
|
+
import { injectSiteSettingsTab } from "@elementor/editor-site-settings";
|
|
3
|
+
|
|
4
|
+
// src/components/agents-settings-tab.tsx
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { useCallback, useState } from "react";
|
|
7
|
+
import { __privateUseListenTo as useListenTo, routeOpenEvent } from "@elementor/editor-v1-adapters";
|
|
8
|
+
import { Box, Stack, TextField, Typography } from "@elementor/ui";
|
|
9
|
+
import { __ } from "@wordpress/i18n";
|
|
10
|
+
|
|
11
|
+
// src/llms-settings.ts
|
|
12
|
+
import { getV1CurrentDocument, setDocumentModifiedStatus } from "@elementor/editor-documents";
|
|
13
|
+
var AGENTS_SETTINGS_KEY = "agents";
|
|
14
|
+
var LLMS_SETTINGS_KEY = "llms";
|
|
15
|
+
function getSiteSettingsBag() {
|
|
16
|
+
const settings = getV1CurrentDocument()?.container?.settings;
|
|
17
|
+
return settings ? settings : null;
|
|
18
|
+
}
|
|
19
|
+
function readAgentsSettings(settings) {
|
|
20
|
+
const agents = settings?.get(AGENTS_SETTINGS_KEY);
|
|
21
|
+
return agents && typeof agents === "object" ? { ...agents } : {};
|
|
22
|
+
}
|
|
23
|
+
function omitLlms(agents) {
|
|
24
|
+
return Object.fromEntries(Object.entries(agents).filter(([key]) => key !== LLMS_SETTINGS_KEY));
|
|
25
|
+
}
|
|
26
|
+
function isEmpty(agents) {
|
|
27
|
+
return 0 === Object.keys(agents).length;
|
|
28
|
+
}
|
|
29
|
+
function readLlmsContent() {
|
|
30
|
+
const llms = readAgentsSettings(getSiteSettingsBag())[LLMS_SETTINGS_KEY];
|
|
31
|
+
return typeof llms === "string" ? llms : "";
|
|
32
|
+
}
|
|
33
|
+
function writeLlmsContent(content) {
|
|
34
|
+
const settings = getSiteSettingsBag();
|
|
35
|
+
if (!settings) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const agents = readAgentsSettings(settings);
|
|
39
|
+
if ("" === content) {
|
|
40
|
+
const remainingAgents = omitLlms(agents);
|
|
41
|
+
settings.set(AGENTS_SETTINGS_KEY, isEmpty(remainingAgents) ? void 0 : remainingAgents);
|
|
42
|
+
} else {
|
|
43
|
+
settings.set(AGENTS_SETTINGS_KEY, { ...agents, [LLMS_SETTINGS_KEY]: content });
|
|
44
|
+
}
|
|
45
|
+
setDocumentModifiedStatus(true);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/components/agents-settings-tab.tsx
|
|
50
|
+
var TAB_ID = "settings-agents";
|
|
51
|
+
var TAB_ROUTE = `panel/global/${TAB_ID}`;
|
|
52
|
+
function AgentsSettingsTab() {
|
|
53
|
+
const [value, setValue] = useState(readLlmsContent);
|
|
54
|
+
const [isSettingsAvailable, setIsSettingsAvailable] = useState(() => null !== getSiteSettingsBag());
|
|
55
|
+
useListenTo([routeOpenEvent(TAB_ROUTE)], () => {
|
|
56
|
+
setIsSettingsAvailable(null !== getSiteSettingsBag());
|
|
57
|
+
setValue(readLlmsContent());
|
|
58
|
+
});
|
|
59
|
+
const handleChange = useCallback((event) => {
|
|
60
|
+
const nextValue = event.target.value;
|
|
61
|
+
setValue(nextValue);
|
|
62
|
+
writeLlmsContent(nextValue);
|
|
63
|
+
}, []);
|
|
64
|
+
return /* @__PURE__ */ React.createElement(Box, { sx: { p: 2 } }, /* @__PURE__ */ React.createElement(Stack, { spacing: 1.5 }, /* @__PURE__ */ React.createElement(Typography, { variant: "subtitle2" }, __("Agents", "elementor")), /* @__PURE__ */ React.createElement(
|
|
65
|
+
TextField,
|
|
66
|
+
{
|
|
67
|
+
label: __("llms.txt", "elementor"),
|
|
68
|
+
value,
|
|
69
|
+
onChange: handleChange,
|
|
70
|
+
multiline: true,
|
|
71
|
+
minRows: 12,
|
|
72
|
+
fullWidth: true,
|
|
73
|
+
disabled: !isSettingsAvailable,
|
|
74
|
+
helperText: isSettingsAvailable ? __("Content served at /llms.txt when saved. Leave empty to disable.", "elementor") : __("Kit settings are unavailable. Reopen Site Settings and try again.", "elementor")
|
|
75
|
+
}
|
|
76
|
+
)));
|
|
77
|
+
}
|
|
78
|
+
var AGENTS_SITE_SETTINGS_TAB_ID = TAB_ID;
|
|
79
|
+
|
|
80
|
+
// src/init.ts
|
|
81
|
+
var EXPERIMENT_NAME = "agents_llms_txt";
|
|
82
|
+
function isAgentsExperimentActive() {
|
|
83
|
+
const features = window.elementorCommon?.config?.experimentalFeatures ?? {};
|
|
84
|
+
return Boolean(features[EXPERIMENT_NAME]);
|
|
85
|
+
}
|
|
86
|
+
function init() {
|
|
87
|
+
if (!isAgentsExperimentActive()) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
injectSiteSettingsTab({
|
|
91
|
+
id: AGENTS_SITE_SETTINGS_TAB_ID,
|
|
92
|
+
component: AgentsSettingsTab
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
AGENTS_SITE_SETTINGS_TAB_ID,
|
|
97
|
+
AgentsSettingsTab,
|
|
98
|
+
init
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/init.ts","../src/components/agents-settings-tab.tsx","../src/llms-settings.ts"],"sourcesContent":["import { injectSiteSettingsTab } from '@elementor/editor-site-settings';\n\nimport { AGENTS_SITE_SETTINGS_TAB_ID, AgentsSettingsTab } from './components/agents-settings-tab';\n\nconst EXPERIMENT_NAME = 'agents_llms_txt';\n\nfunction isAgentsExperimentActive(): boolean {\n\tconst features = window.elementorCommon?.config?.experimentalFeatures ?? {};\n\n\treturn Boolean( features[ EXPERIMENT_NAME ] );\n}\n\nexport function init() {\n\tif ( ! isAgentsExperimentActive() ) {\n\t\treturn;\n\t}\n\n\tinjectSiteSettingsTab( {\n\t\tid: AGENTS_SITE_SETTINGS_TAB_ID,\n\t\tcomponent: AgentsSettingsTab,\n\t} );\n}\n","import * as React from 'react';\nimport { useCallback, useState } from 'react';\nimport { __privateUseListenTo as useListenTo, routeOpenEvent } from '@elementor/editor-v1-adapters';\nimport { Box, Stack, TextField, Typography } from '@elementor/ui';\nimport { __ } from '@wordpress/i18n';\n\nimport { getSiteSettingsBag, readLlmsContent, writeLlmsContent } from '../llms-settings';\n\nconst TAB_ID = 'settings-agents';\nconst TAB_ROUTE = `panel/global/${ TAB_ID }`;\n\nexport function AgentsSettingsTab() {\n\tconst [ value, setValue ] = useState( readLlmsContent );\n\tconst [ isSettingsAvailable, setIsSettingsAvailable ] = useState( () => null !== getSiteSettingsBag() );\n\n\tuseListenTo( [ routeOpenEvent( TAB_ROUTE ) ], () => {\n\t\tsetIsSettingsAvailable( null !== getSiteSettingsBag() );\n\t\tsetValue( readLlmsContent() );\n\t} );\n\n\tconst handleChange = useCallback( ( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\tconst nextValue = event.target.value;\n\t\tsetValue( nextValue );\n\t\twriteLlmsContent( nextValue );\n\t}, [] );\n\n\treturn (\n\t\t<Box sx={ { p: 2 } }>\n\t\t\t<Stack spacing={ 1.5 }>\n\t\t\t\t<Typography variant=\"subtitle2\">{ __( 'Agents', 'elementor' ) }</Typography>\n\t\t\t\t<TextField\n\t\t\t\t\tlabel={ __( 'llms.txt', 'elementor' ) }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ handleChange }\n\t\t\t\t\tmultiline\n\t\t\t\t\tminRows={ 12 }\n\t\t\t\t\tfullWidth\n\t\t\t\t\tdisabled={ ! isSettingsAvailable }\n\t\t\t\t\thelperText={\n\t\t\t\t\t\tisSettingsAvailable\n\t\t\t\t\t\t\t? __( 'Content served at /llms.txt when saved. Leave empty to disable.', 'elementor' )\n\t\t\t\t\t\t\t: __( 'Kit settings are unavailable. Reopen Site Settings and try again.', 'elementor' )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</Stack>\n\t\t</Box>\n\t);\n}\n\nexport const AGENTS_SITE_SETTINGS_TAB_ID = TAB_ID;\n","import { getV1CurrentDocument, setDocumentModifiedStatus } from '@elementor/editor-documents';\n\nexport const AGENTS_SETTINGS_KEY = 'agents';\nexport const LLMS_SETTINGS_KEY = 'llms';\n\ntype AgentsSettings = Record< string, unknown >;\n\ntype SettingsBag = {\n\tget: ( key: string ) => unknown;\n\tset: ( key: string, value: unknown ) => void;\n};\n\nexport function getSiteSettingsBag(): SettingsBag | null {\n\tconst settings = getV1CurrentDocument()?.container?.settings;\n\n\treturn settings ? ( settings as SettingsBag ) : null;\n}\n\nfunction readAgentsSettings( settings: SettingsBag | null ): AgentsSettings {\n\tconst agents = settings?.get( AGENTS_SETTINGS_KEY );\n\n\treturn agents && typeof agents === 'object' ? { ...( agents as AgentsSettings ) } : {};\n}\n\nfunction omitLlms( agents: AgentsSettings ): AgentsSettings {\n\treturn Object.fromEntries( Object.entries( agents ).filter( ( [ key ] ) => key !== LLMS_SETTINGS_KEY ) );\n}\n\nfunction isEmpty( agents: AgentsSettings ): boolean {\n\treturn 0 === Object.keys( agents ).length;\n}\n\nexport function readLlmsContent(): string {\n\tconst llms = readAgentsSettings( getSiteSettingsBag() )[ LLMS_SETTINGS_KEY ];\n\n\treturn typeof llms === 'string' ? llms : '';\n}\n\nexport function writeLlmsContent( content: string ): boolean {\n\tconst settings = getSiteSettingsBag();\n\n\tif ( ! settings ) {\n\t\treturn false;\n\t}\n\n\tconst agents = readAgentsSettings( settings );\n\n\tif ( '' === content ) {\n\t\tconst remainingAgents = omitLlms( agents );\n\n\t\tsettings.set( AGENTS_SETTINGS_KEY, isEmpty( remainingAgents ) ? undefined : remainingAgents );\n\t} else {\n\t\tsettings.set( AGENTS_SETTINGS_KEY, { ...agents, [ LLMS_SETTINGS_KEY ]: content } );\n\t}\n\n\tsetDocumentModifiedStatus( true );\n\n\treturn true;\n}\n"],"mappings":";AAAA,SAAS,6BAA6B;;;ACAtC,YAAY,WAAW;AACvB,SAAS,aAAa,gBAAgB;AACtC,SAAS,wBAAwB,aAAa,sBAAsB;AACpE,SAAS,KAAK,OAAO,WAAW,kBAAkB;AAClD,SAAS,UAAU;;;ACJnB,SAAS,sBAAsB,iCAAiC;AAEzD,IAAM,sBAAsB;AAC5B,IAAM,oBAAoB;AAS1B,SAAS,qBAAyC;AACxD,QAAM,WAAW,qBAAqB,GAAG,WAAW;AAEpD,SAAO,WAAa,WAA4B;AACjD;AAEA,SAAS,mBAAoB,UAA+C;AAC3E,QAAM,SAAS,UAAU,IAAK,mBAAoB;AAElD,SAAO,UAAU,OAAO,WAAW,WAAW,EAAE,GAAK,OAA2B,IAAI,CAAC;AACtF;AAEA,SAAS,SAAU,QAAyC;AAC3D,SAAO,OAAO,YAAa,OAAO,QAAS,MAAO,EAAE,OAAQ,CAAE,CAAE,GAAI,MAAO,QAAQ,iBAAkB,CAAE;AACxG;AAEA,SAAS,QAAS,QAAkC;AACnD,SAAO,MAAM,OAAO,KAAM,MAAO,EAAE;AACpC;AAEO,SAAS,kBAA0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ACV,WAAS;AAAA,MACT,UAAW,CAAE;AAAA,MACb,YACC,sBACG,GAAI,mEAAmE,WAAY,IACnF,GAAI,qEAAqE,WAAY;AAAA;AAAA,EAE1F,CACD,CACD;AAEF;AAEO,IAAM,8BAA8B;;;AD7C3C,IAAM,kBAAkB;AAExB,SAAS,2BAAoC;AAC5C,QAAM,WAAW,OAAO,iBAAiB,QAAQ,wBAAwB,CAAC;AAE1E,SAAO,QAAS,SAAU,eAAgB,CAAE;AAC7C;AAEO,SAAS,OAAO;AACtB,MAAK,CAAE,yBAAyB,GAAI;AACnC;AAAA,EACD;AAEA,wBAAuB;AAAA,IACtB,IAAI;AAAA,IACJ,WAAW;AAAA,EACZ,CAAE;AACH;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elementor/editor-agents",
|
|
3
|
+
"version": "4.3.0-1031",
|
|
4
|
+
"private": false,
|
|
5
|
+
"author": "Elementor Team",
|
|
6
|
+
"homepage": "https://elementor.com/",
|
|
7
|
+
"license": "GPL-3.0-or-later",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"module": "dist/index.mjs",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/elementor/elementor.git",
|
|
22
|
+
"directory": "packages/core/editor-agents"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/elementor/elementor/issues"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"/dist",
|
|
32
|
+
"/src",
|
|
33
|
+
"!**/__tests__"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup --config=../../tsup.build.ts",
|
|
37
|
+
"dev": "tsup --config=../../tsup.dev.ts"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@elementor/editor-documents": "4.3.0-1031",
|
|
41
|
+
"@elementor/editor-site-settings": "4.3.0-1031",
|
|
42
|
+
"@elementor/editor-v1-adapters": "4.3.0-1031",
|
|
43
|
+
"@elementor/ui": "1.37.5",
|
|
44
|
+
"@wordpress/i18n": "^5.13.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": "^18.3.1",
|
|
48
|
+
"react-dom": "^18.3.1"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"tsup": "^8.3.5"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
import { __privateUseListenTo as useListenTo, routeOpenEvent } from '@elementor/editor-v1-adapters';
|
|
4
|
+
import { Box, Stack, TextField, Typography } from '@elementor/ui';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
|
|
7
|
+
import { getSiteSettingsBag, readLlmsContent, writeLlmsContent } from '../llms-settings';
|
|
8
|
+
|
|
9
|
+
const TAB_ID = 'settings-agents';
|
|
10
|
+
const TAB_ROUTE = `panel/global/${ TAB_ID }`;
|
|
11
|
+
|
|
12
|
+
export function AgentsSettingsTab() {
|
|
13
|
+
const [ value, setValue ] = useState( readLlmsContent );
|
|
14
|
+
const [ isSettingsAvailable, setIsSettingsAvailable ] = useState( () => null !== getSiteSettingsBag() );
|
|
15
|
+
|
|
16
|
+
useListenTo( [ routeOpenEvent( TAB_ROUTE ) ], () => {
|
|
17
|
+
setIsSettingsAvailable( null !== getSiteSettingsBag() );
|
|
18
|
+
setValue( readLlmsContent() );
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
const handleChange = useCallback( ( event: React.ChangeEvent< HTMLInputElement > ) => {
|
|
22
|
+
const nextValue = event.target.value;
|
|
23
|
+
setValue( nextValue );
|
|
24
|
+
writeLlmsContent( nextValue );
|
|
25
|
+
}, [] );
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Box sx={ { p: 2 } }>
|
|
29
|
+
<Stack spacing={ 1.5 }>
|
|
30
|
+
<Typography variant="subtitle2">{ __( 'Agents', 'elementor' ) }</Typography>
|
|
31
|
+
<TextField
|
|
32
|
+
label={ __( 'llms.txt', 'elementor' ) }
|
|
33
|
+
value={ value }
|
|
34
|
+
onChange={ handleChange }
|
|
35
|
+
multiline
|
|
36
|
+
minRows={ 12 }
|
|
37
|
+
fullWidth
|
|
38
|
+
disabled={ ! isSettingsAvailable }
|
|
39
|
+
helperText={
|
|
40
|
+
isSettingsAvailable
|
|
41
|
+
? __( 'Content served at /llms.txt when saved. Leave empty to disable.', 'elementor' )
|
|
42
|
+
: __( 'Kit settings are unavailable. Reopen Site Settings and try again.', 'elementor' )
|
|
43
|
+
}
|
|
44
|
+
/>
|
|
45
|
+
</Stack>
|
|
46
|
+
</Box>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const AGENTS_SITE_SETTINGS_TAB_ID = TAB_ID;
|
package/src/index.ts
ADDED
package/src/init.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { injectSiteSettingsTab } from '@elementor/editor-site-settings';
|
|
2
|
+
|
|
3
|
+
import { AGENTS_SITE_SETTINGS_TAB_ID, AgentsSettingsTab } from './components/agents-settings-tab';
|
|
4
|
+
|
|
5
|
+
const EXPERIMENT_NAME = 'agents_llms_txt';
|
|
6
|
+
|
|
7
|
+
function isAgentsExperimentActive(): boolean {
|
|
8
|
+
const features = window.elementorCommon?.config?.experimentalFeatures ?? {};
|
|
9
|
+
|
|
10
|
+
return Boolean( features[ EXPERIMENT_NAME ] );
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function init() {
|
|
14
|
+
if ( ! isAgentsExperimentActive() ) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
injectSiteSettingsTab( {
|
|
19
|
+
id: AGENTS_SITE_SETTINGS_TAB_ID,
|
|
20
|
+
component: AgentsSettingsTab,
|
|
21
|
+
} );
|
|
22
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getV1CurrentDocument, setDocumentModifiedStatus } from '@elementor/editor-documents';
|
|
2
|
+
|
|
3
|
+
export const AGENTS_SETTINGS_KEY = 'agents';
|
|
4
|
+
export const LLMS_SETTINGS_KEY = 'llms';
|
|
5
|
+
|
|
6
|
+
type AgentsSettings = Record< string, unknown >;
|
|
7
|
+
|
|
8
|
+
type SettingsBag = {
|
|
9
|
+
get: ( key: string ) => unknown;
|
|
10
|
+
set: ( key: string, value: unknown ) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function getSiteSettingsBag(): SettingsBag | null {
|
|
14
|
+
const settings = getV1CurrentDocument()?.container?.settings;
|
|
15
|
+
|
|
16
|
+
return settings ? ( settings as SettingsBag ) : null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function readAgentsSettings( settings: SettingsBag | null ): AgentsSettings {
|
|
20
|
+
const agents = settings?.get( AGENTS_SETTINGS_KEY );
|
|
21
|
+
|
|
22
|
+
return agents && typeof agents === 'object' ? { ...( agents as AgentsSettings ) } : {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function omitLlms( agents: AgentsSettings ): AgentsSettings {
|
|
26
|
+
return Object.fromEntries( Object.entries( agents ).filter( ( [ key ] ) => key !== LLMS_SETTINGS_KEY ) );
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isEmpty( agents: AgentsSettings ): boolean {
|
|
30
|
+
return 0 === Object.keys( agents ).length;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function readLlmsContent(): string {
|
|
34
|
+
const llms = readAgentsSettings( getSiteSettingsBag() )[ LLMS_SETTINGS_KEY ];
|
|
35
|
+
|
|
36
|
+
return typeof llms === 'string' ? llms : '';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function writeLlmsContent( content: string ): boolean {
|
|
40
|
+
const settings = getSiteSettingsBag();
|
|
41
|
+
|
|
42
|
+
if ( ! settings ) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const agents = readAgentsSettings( settings );
|
|
47
|
+
|
|
48
|
+
if ( '' === content ) {
|
|
49
|
+
const remainingAgents = omitLlms( agents );
|
|
50
|
+
|
|
51
|
+
settings.set( AGENTS_SETTINGS_KEY, isEmpty( remainingAgents ) ? undefined : remainingAgents );
|
|
52
|
+
} else {
|
|
53
|
+
settings.set( AGENTS_SETTINGS_KEY, { ...agents, [ LLMS_SETTINGS_KEY ]: content } );
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setDocumentModifiedStatus( true );
|
|
57
|
+
|
|
58
|
+
return true;
|
|
59
|
+
}
|