@parhelia/alpaca 0.1.12485 → 0.1.12496
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/componentCommands.d.ts +3 -0
- package/dist/componentCommands.d.ts.map +1 -0
- package/dist/componentCommands.js +67 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentCommands.d.ts","sourceRoot":"","sources":["../src/componentCommands.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,wBAAwB,EAEzB,MAAM,uBAAuB,CAAC;AAK/B,eAAO,MAAM,8BAA8B,EAAE,wBAmB5C,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Check, Square, StopCircle } from "lucide-react";
|
|
3
|
+
const defaultIconSize = 16;
|
|
4
|
+
export const alpacaComponentCommandProvider = async (components, editContext) => {
|
|
5
|
+
const commands = [];
|
|
6
|
+
const linkToMasterCommand = await getLinkToMasterCommand(components, editContext);
|
|
7
|
+
if (linkToMasterCommand)
|
|
8
|
+
commands.push(linkToMasterCommand);
|
|
9
|
+
const inheritChildrenCommand = await getInheritChildrenFromMasterCommand(components, editContext);
|
|
10
|
+
if (inheritChildrenCommand)
|
|
11
|
+
commands.push(inheritChildrenCommand);
|
|
12
|
+
return commands;
|
|
13
|
+
};
|
|
14
|
+
async function getLinkToMasterCommand(components, editContext) {
|
|
15
|
+
if (!components.length)
|
|
16
|
+
return null;
|
|
17
|
+
if (editContext.page?.item?.masterLanguages?.length === 0)
|
|
18
|
+
return null;
|
|
19
|
+
if (components.some((c) => c.layoutId && !editContext.showLayoutComponents)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return getCheckboxCommand(components, editContext, "componentLinkedToMasterLanguage", "Linked To Master Language");
|
|
23
|
+
}
|
|
24
|
+
async function getInheritChildrenFromMasterCommand(components, editContext) {
|
|
25
|
+
if (!components.length)
|
|
26
|
+
return null;
|
|
27
|
+
if (editContext.page?.item?.masterLanguages?.length === 0)
|
|
28
|
+
return null;
|
|
29
|
+
if (components.some((c) => !c.placeholders || c.placeholders.length === 0)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (components.some((c) => c.layoutId && !editContext.showLayoutComponents)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return getCheckboxCommand(components, editContext, "inheritChildrenFromMasterLanguage", "Inherit Children From Master");
|
|
36
|
+
}
|
|
37
|
+
async function getCheckboxCommand(components, editContext, fieldName, label) {
|
|
38
|
+
const datasourceItems = components
|
|
39
|
+
.filter((component) => component.datasourceItem)
|
|
40
|
+
.map((component) => component.datasourceItem);
|
|
41
|
+
if (!datasourceItems.length)
|
|
42
|
+
return null;
|
|
43
|
+
const items = await editContext.itemsRepository.getItems(datasourceItems);
|
|
44
|
+
if (!items.length)
|
|
45
|
+
return null;
|
|
46
|
+
const someLinked = items.some((item) => item.fields.find((field) => field.name === fieldName)?.rawValue === "1");
|
|
47
|
+
const allLinked = items.every((item) => item.fields.find((field) => field.name === fieldName)?.rawValue === "1");
|
|
48
|
+
return {
|
|
49
|
+
id: fieldName,
|
|
50
|
+
icon: allLinked ? (_jsx(Check, { size: defaultIconSize })) : someLinked ? (_jsx(StopCircle, { size: defaultIconSize })) : (_jsx(Square, { size: defaultIconSize })),
|
|
51
|
+
label,
|
|
52
|
+
disabled: () => false,
|
|
53
|
+
execute: async () => {
|
|
54
|
+
items.forEach((item) => {
|
|
55
|
+
const field = item.fields.find((candidate) => candidate.name === fieldName);
|
|
56
|
+
if (!field)
|
|
57
|
+
return;
|
|
58
|
+
editContext.operations.editField({
|
|
59
|
+
field: field.descriptor,
|
|
60
|
+
rawValue: allLinked ? "" : "1",
|
|
61
|
+
refresh: "immediate",
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
visibilityScopes: ["menu", "contextMenu"],
|
|
66
|
+
};
|
|
67
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { EditorConfiguration } from "@parhelia/core";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function configureAlpaca(configuration: EditorConfiguration): EditorConfiguration;
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EAIpB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EAIpB,MAAM,gBAAgB,CAAC;AAuCxB,wBAAgB,eAAe,CAAC,aAAa,EAAE,mBAAmB,uBAgCjE"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { PanelsTopLeft } from "lucide-react";
|
|
|
3
3
|
import { GraphQLIcon, JsonIcon, } from "@parhelia/core";
|
|
4
4
|
import { Layout } from "./Layout";
|
|
5
5
|
import { GraphQL } from "./GraphQL";
|
|
6
|
+
import { alpacaComponentCommandProvider } from "./componentCommands";
|
|
6
7
|
const layoutDebugSidebar = {
|
|
7
8
|
id: "layout",
|
|
8
9
|
title: "Layout",
|
|
@@ -35,7 +36,7 @@ const graphqlSidebar = {
|
|
|
35
36
|
},
|
|
36
37
|
],
|
|
37
38
|
};
|
|
38
|
-
export function
|
|
39
|
+
export function configureAlpaca(configuration) {
|
|
39
40
|
const sidebars = (configuration.editor?.sidebars || []).filter((s) => s.id !== "debug");
|
|
40
41
|
const hasLayoutDebugSidebar = sidebars.some((s) => s.id === layoutDebugSidebar.id);
|
|
41
42
|
const hasGraphqlSidebar = sidebars.some((s) => s.id === graphqlSidebar.id);
|
|
@@ -48,5 +49,14 @@ export function configureAlpacaDebug(configuration) {
|
|
|
48
49
|
...configuration.editor,
|
|
49
50
|
sidebars: nextSidebars,
|
|
50
51
|
};
|
|
52
|
+
const componentCommandProviders = configuration.componentCommands?.providers ?? [];
|
|
53
|
+
if (!componentCommandProviders.includes(alpacaComponentCommandProvider)) {
|
|
54
|
+
configuration.componentCommands = {
|
|
55
|
+
providers: [
|
|
56
|
+
...componentCommandProviders,
|
|
57
|
+
alpacaComponentCommandProvider,
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
51
61
|
return configuration;
|
|
52
62
|
}
|