@measured/puck 0.21.0-canary.304940ae → 0.21.0-canary.3aa27d1d

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.
@@ -84,6 +84,68 @@ var init_react_import = __esm({
84
84
  }
85
85
  });
86
86
 
87
+ // ../../node_modules/classnames/index.js
88
+ var require_classnames = __commonJS({
89
+ "../../node_modules/classnames/index.js"(exports, module) {
90
+ "use strict";
91
+ init_react_import();
92
+ (function() {
93
+ "use strict";
94
+ var hasOwn = {}.hasOwnProperty;
95
+ function classNames() {
96
+ var classes = "";
97
+ for (var i = 0; i < arguments.length; i++) {
98
+ var arg = arguments[i];
99
+ if (arg) {
100
+ classes = appendClass(classes, parseValue(arg));
101
+ }
102
+ }
103
+ return classes;
104
+ }
105
+ function parseValue(arg) {
106
+ if (typeof arg === "string" || typeof arg === "number") {
107
+ return arg;
108
+ }
109
+ if (typeof arg !== "object") {
110
+ return "";
111
+ }
112
+ if (Array.isArray(arg)) {
113
+ return classNames.apply(null, arg);
114
+ }
115
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
116
+ return arg.toString();
117
+ }
118
+ var classes = "";
119
+ for (var key in arg) {
120
+ if (hasOwn.call(arg, key) && arg[key]) {
121
+ classes = appendClass(classes, key);
122
+ }
123
+ }
124
+ return classes;
125
+ }
126
+ function appendClass(value, newClass) {
127
+ if (!newClass) {
128
+ return value;
129
+ }
130
+ if (value) {
131
+ return value + " " + newClass;
132
+ }
133
+ return value + newClass;
134
+ }
135
+ if (typeof module !== "undefined" && module.exports) {
136
+ classNames.default = classNames;
137
+ module.exports = classNames;
138
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
139
+ define("classnames", [], function() {
140
+ return classNames;
141
+ });
142
+ } else {
143
+ window.classNames = classNames;
144
+ }
145
+ })();
146
+ }
147
+ });
148
+
87
149
  // lib/data/walk-tree.ts
88
150
  init_react_import();
89
151
 
@@ -815,6 +877,33 @@ function resolveAllData(_0, _1) {
815
877
  });
816
878
  }
817
879
 
880
+ // lib/get-class-name-factory.ts
881
+ init_react_import();
882
+ var import_classnames = __toESM(require_classnames());
883
+ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
884
+ if (typeof options === "string") {
885
+ const descendant = options;
886
+ const style = styles[`${rootClass}-${descendant}`];
887
+ if (style) {
888
+ return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
889
+ }
890
+ return "";
891
+ } else if (typeof options === "object") {
892
+ const modifiers = options;
893
+ const prefixedModifiers = {};
894
+ for (let modifier in modifiers) {
895
+ prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
896
+ }
897
+ const c = styles[rootClass];
898
+ return config.baseClass + (0, import_classnames.default)(__spreadValues({
899
+ [c]: !!c
900
+ }, prefixedModifiers));
901
+ } else {
902
+ return config.baseClass + styles[rootClass] || "";
903
+ }
904
+ };
905
+ var get_class_name_factory_default = getClassNameFactory;
906
+
818
907
  // lib/data/setup-zone.ts
819
908
  init_react_import();
820
909
  var setupZone = (data, zoneKey) => {
@@ -892,21 +981,197 @@ function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdi
892
981
  );
893
982
  }
894
983
 
984
+ // components/RichTextEditor/lib/use-richtext-renderer.tsx
985
+ init_react_import();
986
+ import { useMemo as useMemo3 } from "react";
987
+
988
+ // components/RichTextEditor/Render.tsx
989
+ init_react_import();
990
+ import { generateHTML, generateJSON } from "@tiptap/html";
991
+ import { useMemo as useMemo2 } from "react";
992
+
993
+ // css-module:/home/runner/work/puck/puck/packages/core/components/RichTextEditor/styles.module.css#css-module
994
+ init_react_import();
995
+ var styles_module_default = { "RichTextEditor": "_RichTextEditor_1819a_1", "RichTextEditor--editor": "_RichTextEditor--editor_1819a_46", "RichTextEditor--disabled": "_RichTextEditor--disabled_1819a_95", "RichTextEditor--isActive": "_RichTextEditor--isActive_1819a_99", "RichTextEditor-menu": "_RichTextEditor-menu_1819a_105" };
996
+
997
+ // components/RichTextEditor/extensions.ts
998
+ init_react_import();
999
+ import { Extension } from "@tiptap/core";
1000
+ import { Blockquote } from "@tiptap/extension-blockquote";
1001
+ import { Bold } from "@tiptap/extension-bold";
1002
+ import { Code } from "@tiptap/extension-code";
1003
+ import { CodeBlock } from "@tiptap/extension-code-block";
1004
+ import { Document } from "@tiptap/extension-document";
1005
+ import { HardBreak } from "@tiptap/extension-hard-break";
1006
+ import { Heading } from "@tiptap/extension-heading";
1007
+ import { HorizontalRule } from "@tiptap/extension-horizontal-rule";
1008
+ import { Italic } from "@tiptap/extension-italic";
1009
+ import { Link } from "@tiptap/extension-link";
1010
+ import {
1011
+ BulletList,
1012
+ ListItem,
1013
+ ListKeymap,
1014
+ OrderedList
1015
+ } from "@tiptap/extension-list";
1016
+ import { Paragraph } from "@tiptap/extension-paragraph";
1017
+ import { Strike } from "@tiptap/extension-strike";
1018
+ import { Text } from "@tiptap/extension-text";
1019
+ import TextAlign from "@tiptap/extension-text-align";
1020
+ import { Underline } from "@tiptap/extension-underline";
1021
+ var defaultPuckRichTextOptions = {
1022
+ textAlign: {
1023
+ types: ["heading", "paragraph"]
1024
+ }
1025
+ };
1026
+ var PuckRichText = Extension.create({
1027
+ name: "puckRichText",
1028
+ addExtensions() {
1029
+ const extensions = [];
1030
+ const options = __spreadValues(__spreadValues({}, this.options), defaultPuckRichTextOptions);
1031
+ if (options.bold !== false) {
1032
+ extensions.push(Bold.configure(options.bold));
1033
+ }
1034
+ if (options.blockquote !== false) {
1035
+ extensions.push(Blockquote.configure(options.blockquote));
1036
+ }
1037
+ if (options.bulletList !== false) {
1038
+ extensions.push(BulletList.configure(options.bulletList));
1039
+ }
1040
+ if (options.code !== false) {
1041
+ extensions.push(Code.configure(options.code));
1042
+ }
1043
+ if (options.codeBlock !== false) {
1044
+ extensions.push(CodeBlock.configure(options.codeBlock));
1045
+ }
1046
+ if (options.document !== false) {
1047
+ extensions.push(Document.configure(options.document));
1048
+ }
1049
+ if (options.hardBreak !== false) {
1050
+ extensions.push(HardBreak.configure(options.hardBreak));
1051
+ }
1052
+ if (options.heading !== false) {
1053
+ extensions.push(Heading.configure(options.heading));
1054
+ }
1055
+ if (options.horizontalRule !== false) {
1056
+ extensions.push(HorizontalRule.configure(options.horizontalRule));
1057
+ }
1058
+ if (options.italic !== false) {
1059
+ extensions.push(Italic.configure(options.italic));
1060
+ }
1061
+ if (options.listItem !== false) {
1062
+ extensions.push(ListItem.configure(options.listItem));
1063
+ }
1064
+ if (options.listKeymap !== false) {
1065
+ extensions.push(ListKeymap.configure(options == null ? void 0 : options.listKeymap));
1066
+ }
1067
+ if (options.link !== false) {
1068
+ extensions.push(Link.configure(options == null ? void 0 : options.link));
1069
+ }
1070
+ if (options.orderedList !== false) {
1071
+ extensions.push(OrderedList.configure(options.orderedList));
1072
+ }
1073
+ if (options.paragraph !== false) {
1074
+ extensions.push(Paragraph.configure(options.paragraph));
1075
+ }
1076
+ if (options.strike !== false) {
1077
+ extensions.push(Strike.configure(options.strike));
1078
+ }
1079
+ if (options.text !== false) {
1080
+ extensions.push(Text.configure(options.text));
1081
+ }
1082
+ if (options.textAlign !== false) {
1083
+ extensions.push(TextAlign.configure(options.textAlign));
1084
+ }
1085
+ if (options.underline !== false) {
1086
+ extensions.push(Underline.configure(options == null ? void 0 : options.underline));
1087
+ }
1088
+ return extensions;
1089
+ }
1090
+ });
1091
+
1092
+ // components/RichTextEditor/Render.tsx
1093
+ import { jsx } from "react/jsx-runtime";
1094
+ var getClassName = get_class_name_factory_default("RichTextEditor", styles_module_default);
1095
+ function RichTextRender({
1096
+ content,
1097
+ field
1098
+ }) {
1099
+ const { tiptap = {}, options } = field;
1100
+ const { extensions = [] } = tiptap;
1101
+ const loadedExtensions = useMemo2(
1102
+ () => [PuckRichText.configure(options), ...extensions],
1103
+ [field, extensions]
1104
+ );
1105
+ const normalized = useMemo2(() => {
1106
+ if (typeof content === "object" && (content == null ? void 0 : content.type) === "doc") {
1107
+ return content;
1108
+ }
1109
+ if (typeof content === "string") {
1110
+ const isHtml = /<\/?[a-z][\s\S]*>/i.test(content);
1111
+ if (isHtml) {
1112
+ return generateJSON(content, loadedExtensions);
1113
+ }
1114
+ return {
1115
+ type: "doc",
1116
+ content: [
1117
+ { type: "paragraph", content: [{ type: "text", text: content }] }
1118
+ ]
1119
+ };
1120
+ }
1121
+ return { type: "doc", content: [] };
1122
+ }, [content, loadedExtensions]);
1123
+ const html = useMemo2(() => {
1124
+ return generateHTML(normalized, loadedExtensions);
1125
+ }, [normalized, loadedExtensions]);
1126
+ return /* @__PURE__ */ jsx("div", { className: getClassName(), children: /* @__PURE__ */ jsx("div", { className: "rich-text", dangerouslySetInnerHTML: { __html: html } }) });
1127
+ }
1128
+
1129
+ // components/RichTextEditor/lib/use-richtext-renderer.tsx
1130
+ import { jsx as jsx2 } from "react/jsx-runtime";
1131
+ function useRichtextRenderer(fields, props) {
1132
+ const findAllRichtextKeys = (fields2) => {
1133
+ if (!fields2) return [];
1134
+ const result = [];
1135
+ for (const [key, field] of Object.entries(fields2)) {
1136
+ if (field.type === "richtext") {
1137
+ result.push(key);
1138
+ }
1139
+ }
1140
+ return result;
1141
+ };
1142
+ const richtextKeys = useMemo3(() => findAllRichtextKeys(fields), [fields]);
1143
+ const richTextRenderer = useMemo3(() => {
1144
+ if (!richtextKeys) return {};
1145
+ return richtextKeys.reduce((acc, key) => {
1146
+ acc[key] = /* @__PURE__ */ jsx2(
1147
+ RichTextRender,
1148
+ {
1149
+ content: props[key],
1150
+ field: fields[key]
1151
+ }
1152
+ );
1153
+ return acc;
1154
+ }, {});
1155
+ }, [richtextKeys, props]);
1156
+ return richTextRenderer;
1157
+ }
1158
+
895
1159
  // components/SlotRender/server.tsx
896
1160
  init_react_import();
897
1161
  import { forwardRef } from "react";
898
- import { jsx } from "react/jsx-runtime";
899
- var SlotRenderPure = (props) => /* @__PURE__ */ jsx(SlotRender, __spreadValues({}, props));
1162
+ import { jsx as jsx3 } from "react/jsx-runtime";
1163
+ var SlotRenderPure = (props) => /* @__PURE__ */ jsx3(SlotRender, __spreadValues({}, props));
900
1164
  var Item = ({
901
1165
  config,
902
1166
  item,
903
1167
  metadata
904
1168
  }) => {
905
1169
  const Component = config.components[item.type];
906
- const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
907
- return /* @__PURE__ */ jsx(
1170
+ const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx3(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
1171
+ const richTextRenderer = useRichtextRenderer(Component.fields, props);
1172
+ return /* @__PURE__ */ jsx3(
908
1173
  Component.render,
909
- __spreadProps(__spreadValues({}, props), {
1174
+ __spreadProps(__spreadValues(__spreadValues({}, props), richTextRenderer), {
910
1175
  puck: __spreadProps(__spreadValues({}, props.puck), {
911
1176
  metadata: metadata || {}
912
1177
  })
@@ -916,11 +1181,11 @@ var Item = ({
916
1181
  var SlotRender = forwardRef(
917
1182
  function SlotRenderInternal({ className, style, content, config, metadata, as }, ref) {
918
1183
  const El = as != null ? as : "div";
919
- return /* @__PURE__ */ jsx(El, { className, style, ref, children: content.map((item) => {
1184
+ return /* @__PURE__ */ jsx3(El, { className, style, ref, children: content.map((item) => {
920
1185
  if (!config.components[item.type]) {
921
1186
  return null;
922
1187
  }
923
- return /* @__PURE__ */ jsx(
1188
+ return /* @__PURE__ */ jsx3(
924
1189
  Item,
925
1190
  {
926
1191
  config,
@@ -941,6 +1206,7 @@ export {
941
1206
  __toESM,
942
1207
  __async,
943
1208
  init_react_import,
1209
+ get_class_name_factory_default,
944
1210
  rootAreaId,
945
1211
  rootZone,
946
1212
  rootDroppableId,
@@ -954,9 +1220,13 @@ export {
954
1220
  getChanged,
955
1221
  resolveComponentData,
956
1222
  defaultAppState,
1223
+ PuckRichText,
1224
+ styles_module_default,
957
1225
  useFieldTransforms,
958
1226
  getSlotTransform,
959
1227
  useSlots,
1228
+ RichTextRender,
1229
+ useRichtextRenderer,
960
1230
  SlotRenderPure,
961
1231
  SlotRender,
962
1232
  toComponent,
@@ -964,3 +1234,12 @@ export {
964
1234
  transformProps,
965
1235
  resolveAllData
966
1236
  };
1237
+ /*! Bundled license information:
1238
+
1239
+ classnames/index.js:
1240
+ (*!
1241
+ Copyright (c) 2018 Jed Watson.
1242
+ Licensed under the MIT License (MIT), see
1243
+ http://jedwatson.github.io/classnames
1244
+ *)
1245
+ */