@webstudio-is/react-sdk 0.196.0 → 0.197.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.
- package/lib/index.js +7 -318
- package/lib/runtime.js +3 -1
- package/lib/types/core-components.d.ts +1 -1
- package/lib/types/css/css.d.ts +1 -2
- package/lib/types/embed-template.d.ts +9 -2260
- package/lib/types/index.d.ts +0 -2
- package/lib/types/instance-utils.d.ts +1 -2
- package/lib/types/runtime.d.ts +5 -0
- package/package.json +9 -9
- package/lib/types/components/component-meta.d.ts +0 -2121
- package/lib/types/prop-meta.d.ts +0 -434
package/lib/index.js
CHANGED
|
@@ -611,7 +611,10 @@ var generateCss = ({
|
|
|
611
611
|
}
|
|
612
612
|
let descendantSuffix = "";
|
|
613
613
|
const instance = instances.get(instanceId);
|
|
614
|
-
if (instance
|
|
614
|
+
if (instance === void 0) {
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
if (instance.component === descendantComponent) {
|
|
615
618
|
const parentId = parentIdByInstanceId.get(instanceId);
|
|
616
619
|
const descendantSelector = descendantSelectorByInstanceId.get(instanceId);
|
|
617
620
|
if (parentId && descendantSelector) {
|
|
@@ -619,8 +622,9 @@ var generateCss = ({
|
|
|
619
622
|
instanceId = parentId;
|
|
620
623
|
}
|
|
621
624
|
}
|
|
622
|
-
const meta =
|
|
623
|
-
const
|
|
625
|
+
const meta = componentMetas.get(instance.component);
|
|
626
|
+
const [_namespace, shortName] = parseComponentName(instance.component);
|
|
627
|
+
const baseName = instance.label ?? meta?.label ?? shortName;
|
|
624
628
|
const className = `w-${scope.getName(instanceId, baseName)}`;
|
|
625
629
|
if (atomic === false) {
|
|
626
630
|
let classList = classes.get(instanceId);
|
|
@@ -777,262 +781,12 @@ var isAttributeNameSafe = (attributeName) => {
|
|
|
777
781
|
return false;
|
|
778
782
|
};
|
|
779
783
|
|
|
780
|
-
// src/prop-meta.ts
|
|
781
|
-
import { z } from "zod";
|
|
782
|
-
var common = {
|
|
783
|
-
label: z.string().optional(),
|
|
784
|
-
description: z.string().optional(),
|
|
785
|
-
required: z.boolean()
|
|
786
|
-
};
|
|
787
|
-
var Number = z.object({
|
|
788
|
-
...common,
|
|
789
|
-
control: z.literal("number"),
|
|
790
|
-
type: z.literal("number"),
|
|
791
|
-
defaultValue: z.number().optional()
|
|
792
|
-
});
|
|
793
|
-
var Range = z.object({
|
|
794
|
-
...common,
|
|
795
|
-
control: z.literal("range"),
|
|
796
|
-
type: z.literal("number"),
|
|
797
|
-
defaultValue: z.number().optional()
|
|
798
|
-
});
|
|
799
|
-
var Text = z.object({
|
|
800
|
-
...common,
|
|
801
|
-
control: z.literal("text"),
|
|
802
|
-
type: z.literal("string"),
|
|
803
|
-
defaultValue: z.string().optional(),
|
|
804
|
-
/**
|
|
805
|
-
* The number of rows in <textarea>. If set to 0 an <input> will be used instead.
|
|
806
|
-
* In line with Storybook team's plan: https://github.com/storybookjs/storybook/issues/21100
|
|
807
|
-
*/
|
|
808
|
-
rows: z.number().optional()
|
|
809
|
-
});
|
|
810
|
-
var Code = z.object({
|
|
811
|
-
...common,
|
|
812
|
-
control: z.literal("code"),
|
|
813
|
-
type: z.literal("string"),
|
|
814
|
-
language: z.union([z.literal("html"), z.literal("markdown")]),
|
|
815
|
-
defaultValue: z.string().optional()
|
|
816
|
-
});
|
|
817
|
-
var CodeText = z.object({
|
|
818
|
-
...common,
|
|
819
|
-
control: z.literal("codetext"),
|
|
820
|
-
type: z.literal("string"),
|
|
821
|
-
defaultValue: z.string().optional()
|
|
822
|
-
});
|
|
823
|
-
var Color = z.object({
|
|
824
|
-
...common,
|
|
825
|
-
control: z.literal("color"),
|
|
826
|
-
type: z.literal("string"),
|
|
827
|
-
defaultValue: z.string().optional()
|
|
828
|
-
});
|
|
829
|
-
var Boolean = z.object({
|
|
830
|
-
...common,
|
|
831
|
-
control: z.literal("boolean"),
|
|
832
|
-
type: z.literal("boolean"),
|
|
833
|
-
defaultValue: z.boolean().optional()
|
|
834
|
-
});
|
|
835
|
-
var Radio = z.object({
|
|
836
|
-
...common,
|
|
837
|
-
control: z.literal("radio"),
|
|
838
|
-
type: z.literal("string"),
|
|
839
|
-
defaultValue: z.string().optional(),
|
|
840
|
-
options: z.array(z.string())
|
|
841
|
-
});
|
|
842
|
-
var InlineRadio = z.object({
|
|
843
|
-
...common,
|
|
844
|
-
control: z.literal("inline-radio"),
|
|
845
|
-
type: z.literal("string"),
|
|
846
|
-
defaultValue: z.string().optional(),
|
|
847
|
-
options: z.array(z.string())
|
|
848
|
-
});
|
|
849
|
-
var Select = z.object({
|
|
850
|
-
...common,
|
|
851
|
-
control: z.literal("select"),
|
|
852
|
-
type: z.literal("string"),
|
|
853
|
-
defaultValue: z.string().optional(),
|
|
854
|
-
options: z.array(z.string())
|
|
855
|
-
});
|
|
856
|
-
var Check = z.object({
|
|
857
|
-
...common,
|
|
858
|
-
control: z.literal("check"),
|
|
859
|
-
type: z.literal("string[]"),
|
|
860
|
-
defaultValue: z.array(z.string()).optional(),
|
|
861
|
-
options: z.array(z.string())
|
|
862
|
-
});
|
|
863
|
-
var InlineCheck = z.object({
|
|
864
|
-
...common,
|
|
865
|
-
control: z.literal("inline-check"),
|
|
866
|
-
type: z.literal("string[]"),
|
|
867
|
-
defaultValue: z.array(z.string()).optional(),
|
|
868
|
-
options: z.array(z.string())
|
|
869
|
-
});
|
|
870
|
-
var MultiSelect = z.object({
|
|
871
|
-
...common,
|
|
872
|
-
control: z.literal("multi-select"),
|
|
873
|
-
type: z.literal("string[]"),
|
|
874
|
-
defaultValue: z.array(z.string()).optional(),
|
|
875
|
-
options: z.array(z.string())
|
|
876
|
-
});
|
|
877
|
-
var File = z.object({
|
|
878
|
-
...common,
|
|
879
|
-
control: z.literal("file"),
|
|
880
|
-
type: z.literal("string"),
|
|
881
|
-
defaultValue: z.string().optional(),
|
|
882
|
-
/** https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept */
|
|
883
|
-
accept: z.string().optional()
|
|
884
|
-
});
|
|
885
|
-
var Url = z.object({
|
|
886
|
-
...common,
|
|
887
|
-
control: z.literal("url"),
|
|
888
|
-
type: z.literal("string"),
|
|
889
|
-
defaultValue: z.string().optional()
|
|
890
|
-
});
|
|
891
|
-
var Json = z.object({
|
|
892
|
-
...common,
|
|
893
|
-
control: z.literal("json"),
|
|
894
|
-
type: z.literal("json"),
|
|
895
|
-
defaultValue: z.unknown().optional()
|
|
896
|
-
});
|
|
897
|
-
var Date = z.object({
|
|
898
|
-
...common,
|
|
899
|
-
control: z.literal("date"),
|
|
900
|
-
// @todo not sure what type should be here
|
|
901
|
-
// (we don't support Date yet, added for completeness)
|
|
902
|
-
type: z.literal("string"),
|
|
903
|
-
defaultValue: z.string().optional()
|
|
904
|
-
});
|
|
905
|
-
var Action = z.object({
|
|
906
|
-
...common,
|
|
907
|
-
control: z.literal("action"),
|
|
908
|
-
type: z.literal("action"),
|
|
909
|
-
defaultValue: z.undefined().optional()
|
|
910
|
-
});
|
|
911
|
-
var TextContent = z.object({
|
|
912
|
-
...common,
|
|
913
|
-
control: z.literal("textContent"),
|
|
914
|
-
type: z.literal("string"),
|
|
915
|
-
defaultValue: z.string().optional()
|
|
916
|
-
});
|
|
917
|
-
var PropMeta = z.union([
|
|
918
|
-
Number,
|
|
919
|
-
Range,
|
|
920
|
-
Text,
|
|
921
|
-
Code,
|
|
922
|
-
CodeText,
|
|
923
|
-
Color,
|
|
924
|
-
Boolean,
|
|
925
|
-
Radio,
|
|
926
|
-
InlineRadio,
|
|
927
|
-
Select,
|
|
928
|
-
MultiSelect,
|
|
929
|
-
Check,
|
|
930
|
-
InlineCheck,
|
|
931
|
-
File,
|
|
932
|
-
Url,
|
|
933
|
-
Json,
|
|
934
|
-
Date,
|
|
935
|
-
Action,
|
|
936
|
-
TextContent
|
|
937
|
-
]);
|
|
938
|
-
|
|
939
|
-
// src/components/component-meta.ts
|
|
940
|
-
import { z as z3 } from "zod";
|
|
941
|
-
import { Matchers } from "@webstudio-is/sdk";
|
|
942
|
-
|
|
943
784
|
// src/embed-template.ts
|
|
944
|
-
import { z as z2 } from "zod";
|
|
945
785
|
import { nanoid } from "nanoid";
|
|
946
786
|
import {
|
|
947
787
|
encodeDataSourceVariable,
|
|
948
788
|
transpileExpression
|
|
949
789
|
} from "@webstudio-is/sdk";
|
|
950
|
-
import { StyleValue } from "@webstudio-is/css-engine";
|
|
951
|
-
var EmbedTemplateText = z2.object({
|
|
952
|
-
type: z2.literal("text"),
|
|
953
|
-
value: z2.string(),
|
|
954
|
-
placeholder: z2.boolean().optional()
|
|
955
|
-
});
|
|
956
|
-
var EmbedTemplateExpression = z2.object({
|
|
957
|
-
type: z2.literal("expression"),
|
|
958
|
-
value: z2.string()
|
|
959
|
-
});
|
|
960
|
-
var EmbedTemplateVariable = z2.object({
|
|
961
|
-
alias: z2.optional(z2.string()),
|
|
962
|
-
initialValue: z2.unknown()
|
|
963
|
-
});
|
|
964
|
-
var EmbedTemplateProp = z2.union([
|
|
965
|
-
z2.object({
|
|
966
|
-
type: z2.literal("number"),
|
|
967
|
-
name: z2.string(),
|
|
968
|
-
value: z2.number()
|
|
969
|
-
}),
|
|
970
|
-
z2.object({
|
|
971
|
-
type: z2.literal("string"),
|
|
972
|
-
name: z2.string(),
|
|
973
|
-
value: z2.string()
|
|
974
|
-
}),
|
|
975
|
-
z2.object({
|
|
976
|
-
type: z2.literal("boolean"),
|
|
977
|
-
name: z2.string(),
|
|
978
|
-
value: z2.boolean()
|
|
979
|
-
}),
|
|
980
|
-
z2.object({
|
|
981
|
-
type: z2.literal("string[]"),
|
|
982
|
-
name: z2.string(),
|
|
983
|
-
value: z2.array(z2.string())
|
|
984
|
-
}),
|
|
985
|
-
z2.object({
|
|
986
|
-
type: z2.literal("json"),
|
|
987
|
-
name: z2.string(),
|
|
988
|
-
value: z2.unknown()
|
|
989
|
-
}),
|
|
990
|
-
z2.object({
|
|
991
|
-
type: z2.literal("expression"),
|
|
992
|
-
name: z2.string(),
|
|
993
|
-
code: z2.string()
|
|
994
|
-
}),
|
|
995
|
-
z2.object({
|
|
996
|
-
type: z2.literal("parameter"),
|
|
997
|
-
name: z2.string(),
|
|
998
|
-
variableName: z2.string(),
|
|
999
|
-
variableAlias: z2.optional(z2.string())
|
|
1000
|
-
}),
|
|
1001
|
-
z2.object({
|
|
1002
|
-
type: z2.literal("action"),
|
|
1003
|
-
name: z2.string(),
|
|
1004
|
-
value: z2.array(
|
|
1005
|
-
z2.object({
|
|
1006
|
-
type: z2.literal("execute"),
|
|
1007
|
-
args: z2.optional(z2.array(z2.string())),
|
|
1008
|
-
code: z2.string()
|
|
1009
|
-
})
|
|
1010
|
-
)
|
|
1011
|
-
})
|
|
1012
|
-
]);
|
|
1013
|
-
var EmbedTemplateStyleDeclRaw = z2.object({
|
|
1014
|
-
// State selector, e.g. :hover
|
|
1015
|
-
state: z2.optional(z2.string()),
|
|
1016
|
-
property: z2.string(),
|
|
1017
|
-
value: StyleValue
|
|
1018
|
-
});
|
|
1019
|
-
var EmbedTemplateStyleDecl = EmbedTemplateStyleDeclRaw;
|
|
1020
|
-
var EmbedTemplateInstance = z2.lazy(
|
|
1021
|
-
() => z2.object({
|
|
1022
|
-
type: z2.literal("instance"),
|
|
1023
|
-
component: z2.string(),
|
|
1024
|
-
label: z2.optional(z2.string()),
|
|
1025
|
-
variables: z2.optional(z2.record(z2.string(), EmbedTemplateVariable)),
|
|
1026
|
-
props: z2.optional(z2.array(EmbedTemplateProp)),
|
|
1027
|
-
styles: z2.optional(z2.array(EmbedTemplateStyleDecl)),
|
|
1028
|
-
children: WsEmbedTemplate
|
|
1029
|
-
})
|
|
1030
|
-
);
|
|
1031
|
-
var WsEmbedTemplate = z2.lazy(
|
|
1032
|
-
() => z2.array(
|
|
1033
|
-
z2.union([EmbedTemplateInstance, EmbedTemplateText, EmbedTemplateExpression])
|
|
1034
|
-
)
|
|
1035
|
-
);
|
|
1036
790
|
var getVariablValue = (value) => {
|
|
1037
791
|
if (typeof value === "string") {
|
|
1038
792
|
return { type: "string", value };
|
|
@@ -1315,62 +1069,6 @@ var namespaceMeta = (meta, namespace, components) => {
|
|
|
1315
1069
|
return newMeta;
|
|
1316
1070
|
};
|
|
1317
1071
|
|
|
1318
|
-
// src/components/component-meta.ts
|
|
1319
|
-
var WsComponentPropsMeta = z3.object({
|
|
1320
|
-
props: z3.record(PropMeta),
|
|
1321
|
-
// Props that will be always visible in properties panel.
|
|
1322
|
-
initialProps: z3.array(z3.string()).optional()
|
|
1323
|
-
});
|
|
1324
|
-
var componentCategories = [
|
|
1325
|
-
"general",
|
|
1326
|
-
"typography",
|
|
1327
|
-
"media",
|
|
1328
|
-
"data",
|
|
1329
|
-
"forms",
|
|
1330
|
-
"localization",
|
|
1331
|
-
"radix",
|
|
1332
|
-
"xml",
|
|
1333
|
-
"hidden",
|
|
1334
|
-
"internal"
|
|
1335
|
-
];
|
|
1336
|
-
var stateCategories = ["states", "component-states"];
|
|
1337
|
-
var ComponentState = z3.object({
|
|
1338
|
-
category: z3.enum(stateCategories).optional(),
|
|
1339
|
-
selector: z3.string(),
|
|
1340
|
-
label: z3.string()
|
|
1341
|
-
});
|
|
1342
|
-
var defaultStates = [
|
|
1343
|
-
{ selector: ":hover", label: "Hover" },
|
|
1344
|
-
{ selector: ":active", label: "Active" },
|
|
1345
|
-
{ selector: ":focus", label: "Focus" },
|
|
1346
|
-
{ selector: ":focus-visible", label: "Focus Visible" },
|
|
1347
|
-
{ selector: ":focus-within", label: "Focus Within" }
|
|
1348
|
-
];
|
|
1349
|
-
var WsComponentMeta = z3.object({
|
|
1350
|
-
category: z3.enum(componentCategories).optional(),
|
|
1351
|
-
// container - can accept other components with dnd or be edited as text
|
|
1352
|
-
// control - usually form controls like inputs, without children
|
|
1353
|
-
// embed - images, videos or other embeddable components, without children
|
|
1354
|
-
// rich-text-child - formatted text fragment, not listed in components list
|
|
1355
|
-
type: z3.enum(["container", "control", "embed", "rich-text-child"]),
|
|
1356
|
-
constraints: Matchers.optional(),
|
|
1357
|
-
// when this field is specified component receives
|
|
1358
|
-
// prop with index of same components withiin specified ancestor
|
|
1359
|
-
// important to automatically enumerate collections without
|
|
1360
|
-
// naming every item manually
|
|
1361
|
-
indexWithinAncestor: z3.optional(z3.string()),
|
|
1362
|
-
stylable: z3.optional(z3.boolean()),
|
|
1363
|
-
label: z3.optional(z3.string()),
|
|
1364
|
-
description: z3.string().optional(),
|
|
1365
|
-
icon: z3.string(),
|
|
1366
|
-
presetStyle: z3.optional(
|
|
1367
|
-
z3.record(z3.string(), z3.array(EmbedTemplateStyleDecl))
|
|
1368
|
-
),
|
|
1369
|
-
states: z3.optional(z3.array(ComponentState)),
|
|
1370
|
-
template: z3.optional(WsEmbedTemplate),
|
|
1371
|
-
order: z3.number().optional()
|
|
1372
|
-
});
|
|
1373
|
-
|
|
1374
1072
|
// src/instance-utils.ts
|
|
1375
1073
|
var getIndexesWithinAncestors = (metas, instances, rootIds) => {
|
|
1376
1074
|
const ancestors = /* @__PURE__ */ new Set();
|
|
@@ -1790,12 +1488,6 @@ var generateWebstudioComponent = ({
|
|
|
1790
1488
|
return generatedComponent;
|
|
1791
1489
|
};
|
|
1792
1490
|
export {
|
|
1793
|
-
EmbedTemplateInstance,
|
|
1794
|
-
EmbedTemplateProp,
|
|
1795
|
-
EmbedTemplateStyleDecl,
|
|
1796
|
-
PropMeta,
|
|
1797
|
-
WsComponentMeta,
|
|
1798
|
-
WsEmbedTemplate,
|
|
1799
1491
|
addGlobalRules,
|
|
1800
1492
|
blockComponent,
|
|
1801
1493
|
blockTemplateComponent,
|
|
@@ -1803,11 +1495,9 @@ export {
|
|
|
1803
1495
|
collapsedAttribute,
|
|
1804
1496
|
collectionComponent,
|
|
1805
1497
|
componentAttribute,
|
|
1806
|
-
componentCategories,
|
|
1807
1498
|
coreMetas,
|
|
1808
1499
|
corePropsMetas,
|
|
1809
1500
|
createImageValueTransformer,
|
|
1810
|
-
defaultStates,
|
|
1811
1501
|
descendantComponent,
|
|
1812
1502
|
editablePlaceholderVariable,
|
|
1813
1503
|
editingPlaceholderVariable,
|
|
@@ -1829,6 +1519,5 @@ export {
|
|
|
1829
1519
|
rootComponent,
|
|
1830
1520
|
selectorIdAttribute,
|
|
1831
1521
|
showAttribute,
|
|
1832
|
-
stateCategories,
|
|
1833
1522
|
textContentAttribute
|
|
1834
1523
|
};
|
package/lib/runtime.js
CHANGED
|
@@ -48,6 +48,7 @@ var useVariableState = (initialState) => {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
// src/runtime.ts
|
|
51
|
+
var xmlNodeTagSuffix = "-ws-xml-node-fb77f896-8e96-40b9-b8f8-90a4e70d724a";
|
|
51
52
|
var getIndexWithinAncestorFromComponentProps = (props) => {
|
|
52
53
|
return props["data-ws-index"];
|
|
53
54
|
};
|
|
@@ -56,5 +57,6 @@ export {
|
|
|
56
57
|
getClosestInstance,
|
|
57
58
|
getIndexWithinAncestorFromComponentProps,
|
|
58
59
|
useResource,
|
|
59
|
-
useVariableState
|
|
60
|
+
useVariableState,
|
|
61
|
+
xmlNodeTagSuffix
|
|
60
62
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WsComponentMeta } from "
|
|
1
|
+
import type { WsComponentMeta } from "@webstudio-is/sdk";
|
|
2
2
|
export declare const rootComponent = "ws:root";
|
|
3
3
|
export declare const portalComponent = "Slot";
|
|
4
4
|
export declare const collectionComponent = "ws:collection";
|
package/lib/types/css/css.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type TransformValue } from "@webstudio-is/css-engine";
|
|
2
|
-
import { type Assets, type Breakpoints, type Instances, type Props, type StyleSourceSelections, type Styles } from "@webstudio-is/sdk";
|
|
3
|
-
import type { WsComponentMeta } from "../components/component-meta";
|
|
2
|
+
import { type Assets, type Breakpoints, type Instances, type Props, type StyleSourceSelections, type Styles, type WsComponentMeta } from "@webstudio-is/sdk";
|
|
4
3
|
export type CssConfig = {
|
|
5
4
|
assets: Assets;
|
|
6
5
|
instances: Instances;
|