@raketa-builder/image-input 1.3.5 → 1.3.8

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,66 @@
1
+ import { __spreadProps, __spreadValues } from './chunk-ORMEWXMH.js';
2
+
3
+ const serialize = (params) => Object.keys(params).map((k) => encodeURIComponent(k) + "=" + encodeURIComponent(params[k])).join("&");
4
+ const get = (url, params = {}, opts = {}) => fetch(`${url}?${serialize(params)}`, opts);
5
+ const patch = (url, params = {}, opts = {}) => fetch(
6
+ url,
7
+ Object.assign(
8
+ {
9
+ method: "PATCH",
10
+ credentials: "same-origin",
11
+ body: JSON.stringify(params)
12
+ },
13
+ opts
14
+ )
15
+ );
16
+ const post = (url, params = {}, opts = {}) => fetch(
17
+ url,
18
+ Object.assign(
19
+ {
20
+ method: "POST",
21
+ credentials: "same-origin",
22
+ body: JSON.stringify(params)
23
+ },
24
+ opts
25
+ )
26
+ );
27
+ const del = (url, params = {}, opts = {}) => fetch(
28
+ url,
29
+ Object.assign(
30
+ {
31
+ method: "DELETE",
32
+ credentials: "same-origin",
33
+ body: JSON.stringify(params)
34
+ },
35
+ opts
36
+ )
37
+ );
38
+ class MediaManager {
39
+ constructor(baseUrl) {
40
+ this.baseUrl = baseUrl;
41
+ }
42
+ findAll(callback, params = {}) {
43
+ get(`${this.baseUrl}images`, __spreadProps(__spreadValues({}, params), { page_size: 100 })).then((r) => r.json()).then((images) => callback(images));
44
+ }
45
+ uploadFile(file, callback) {
46
+ const body = new FormData();
47
+ body.append("image[asset]", file);
48
+ post(`${this.baseUrl}images`, {}, { body }).then((r) => r.json()).then((image) => callback(image));
49
+ }
50
+ update(image, params, callback) {
51
+ patch(
52
+ `${this.baseUrl}images/${image.id}`,
53
+ { image: params },
54
+ { headers: { "content-type": "application/json" } }
55
+ ).then((r) => r.json()).then((image2) => callback(image2));
56
+ }
57
+ destroy(image, callback) {
58
+ del(
59
+ `${this.baseUrl}images/${image.id}`,
60
+ {},
61
+ { headers: { "content-type": "application/json" } }
62
+ ).then((r) => r.json()).then((image2) => callback(image2));
63
+ }
64
+ }
65
+
66
+ export { MediaManager as default };
@@ -0,0 +1,7 @@
1
+ import './chunk-ORMEWXMH.js';
2
+ import React from 'react';
3
+
4
+ const MediaManagerContext = React.createContext({});
5
+ var MediaManagerContext_default = MediaManagerContext;
6
+
7
+ export { MediaManagerContext_default as default };
@@ -0,0 +1,33 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ export { __objRest, __spreadProps, __spreadValues };
@@ -0,0 +1,40 @@
1
+ import { __objRest, __spreadValues } from '../chunk-ORMEWXMH.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import 'react';
4
+ import { Modal, Button, cn } from '@raketa-builder/ui';
5
+
6
+ const ModalContent = (_a) => {
7
+ var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
8
+ return /* @__PURE__ */ jsx(
9
+ "div",
10
+ __spreadValues({
11
+ className: cn("r-reset", "r-image-picker-modal-content", className)
12
+ }, rest)
13
+ );
14
+ };
15
+ const ModalFooter = (_c) => {
16
+ var _d = _c, { className } = _d, rest = __objRest(_d, ["className"]);
17
+ return /* @__PURE__ */ jsx(
18
+ "div",
19
+ __spreadValues({
20
+ className: cn("r-reset", "r-image-picker-modal-footer", className)
21
+ }, rest)
22
+ );
23
+ };
24
+ const Dialog = ({
25
+ onClose,
26
+ title,
27
+ children,
28
+ primaryLabel,
29
+ secondaryLabel = "Cancel",
30
+ onPrimary
31
+ }) => /* @__PURE__ */ jsxs(Modal, { title, onClose, children: [
32
+ /* @__PURE__ */ jsx(ModalContent, { children }),
33
+ (primaryLabel || secondaryLabel) && /* @__PURE__ */ jsxs(ModalFooter, { children: [
34
+ primaryLabel && /* @__PURE__ */ jsx(Button, { type: "button", variant: "primary", onClick: onPrimary, children: primaryLabel }),
35
+ secondaryLabel && /* @__PURE__ */ jsx(Button, { type: "button", variant: "secondary", onClick: onClose, children: secondaryLabel })
36
+ ] })
37
+ ] });
38
+ var Dialog_default = Dialog;
39
+
40
+ export { Dialog_default as default };
@@ -0,0 +1,39 @@
1
+ import { __spreadValues } from '../chunk-ORMEWXMH.js';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import 'react';
4
+ import { FormGroup, Label, Textarea, Input, P } from '@raketa-builder/ui';
5
+ import { randomString } from '../lists';
6
+
7
+ const TextField = (props) => {
8
+ const id = randomString();
9
+ const { label, hint, multiline, onChange } = props;
10
+ const inputProps = Object.assign({}, props);
11
+ delete inputProps.label;
12
+ delete inputProps.hint;
13
+ delete inputProps.multiline;
14
+ delete inputProps.onChange;
15
+ const Component = multiline ? Textarea : Input;
16
+ return /* @__PURE__ */ jsxs(FormGroup, { children: [
17
+ label ? /* @__PURE__ */ jsx(Label, { htmlFor: id, error: props.error, children: label }) : "",
18
+ /* @__PURE__ */ jsx(
19
+ Component,
20
+ __spreadValues({
21
+ id,
22
+ onChange: (e) => onChange(e.target.value)
23
+ }, inputProps)
24
+ ),
25
+ hint ? /* @__PURE__ */ jsx(P, { children: hint }) : ""
26
+ ] });
27
+ };
28
+ const TextInput = ({ label, onChange, value = "", placeholder = "" }) => /* @__PURE__ */ jsx(
29
+ TextField,
30
+ {
31
+ label,
32
+ value,
33
+ placeholder,
34
+ onChange
35
+ }
36
+ );
37
+ var TextInput_default = TextInput;
38
+
39
+ export { TextInput_default as default };