avo-rhino_field 0.0.11 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7aec35556234089518c72a1314cecb1836e3f47fcfc6cb89fc849175be65561
4
- data.tar.gz: 3822aa64d2f78d877541a014cb28523b78eae4e464d001ae56793cf00b20c50d
3
+ metadata.gz: f53dc33bee0399e4168856086147e924ec745e4fd5e19f64d224d5a08013aa27
4
+ data.tar.gz: d3bcfef47a5e00b16688a1269f5eef46b493b06abc1ea64ca4c4f9c7f20fbad2
5
5
  SHA512:
6
- metadata.gz: 3eda4c22cc990b70437fa1c9a402114728df1911c98eb02cc4c896c45c15c4e2a1d7c4af415356f02672aa2a3a2437799e486b42c2b3f8e236e9c2edcac81286
7
- data.tar.gz: afff2c7d30daf2f51fcb4e18025edc4f684ec9f5dad3158a85765b6bd3c4e1bf7f4e53f1a0ead5d20d778ffe2290ab9ba5590e9cc4d9b72c534e7489b9574372
6
+ metadata.gz: 610cc47bd746312b5008fb09f1c779a57e8bd714f229ff67461e92b6db5f8e786fe113adcd5701aebbc541c802db2a8a1a1463b384866eca28da5b1b0c96901b
7
+ data.tar.gz: c00b3070dfe6479b3bc56ac1f1c97358bb39bd93ac4308c1f22a54dfb9bc696d9a9c8bcc04f5b1d1a6e6ceffd04648600e19e4ab079fa29b12577e96ea1bb80c
@@ -29286,6 +29286,287 @@ img.ProseMirror-separator {
29286
29286
  }
29287
29287
  };
29288
29288
 
29289
+ // node_modules/@rails/request.js/src/fetch_response.js
29290
+ var FetchResponse = class {
29291
+ constructor(response) {
29292
+ this.response = response;
29293
+ }
29294
+ get statusCode() {
29295
+ return this.response.status;
29296
+ }
29297
+ get redirected() {
29298
+ return this.response.redirected;
29299
+ }
29300
+ get ok() {
29301
+ return this.response.ok;
29302
+ }
29303
+ get unauthenticated() {
29304
+ return this.statusCode === 401;
29305
+ }
29306
+ get unprocessableEntity() {
29307
+ return this.statusCode === 422;
29308
+ }
29309
+ get authenticationURL() {
29310
+ return this.response.headers.get("WWW-Authenticate");
29311
+ }
29312
+ get contentType() {
29313
+ const contentType = this.response.headers.get("Content-Type") || "";
29314
+ return contentType.replace(/;.*$/, "");
29315
+ }
29316
+ get headers() {
29317
+ return this.response.headers;
29318
+ }
29319
+ get html() {
29320
+ if (this.contentType.match(/^(application|text)\/(html|xhtml\+xml)$/)) {
29321
+ return this.text;
29322
+ }
29323
+ return Promise.reject(new Error(`Expected an HTML response but got "${this.contentType}" instead`));
29324
+ }
29325
+ get json() {
29326
+ if (this.contentType.match(/^application\/.*json$/)) {
29327
+ return this.responseJson || (this.responseJson = this.response.json());
29328
+ }
29329
+ return Promise.reject(new Error(`Expected a JSON response but got "${this.contentType}" instead`));
29330
+ }
29331
+ get text() {
29332
+ return this.responseText || (this.responseText = this.response.text());
29333
+ }
29334
+ get isTurboStream() {
29335
+ return this.contentType.match(/^text\/vnd\.turbo-stream\.html/);
29336
+ }
29337
+ get isScript() {
29338
+ return this.contentType.match(/\b(?:java|ecma)script\b/);
29339
+ }
29340
+ async renderTurboStream() {
29341
+ if (this.isTurboStream) {
29342
+ if (window.Turbo) {
29343
+ await window.Turbo.renderStreamMessage(await this.text);
29344
+ } else {
29345
+ console.warn("You must set `window.Turbo = Turbo` to automatically process Turbo Stream events with request.js");
29346
+ }
29347
+ } else {
29348
+ return Promise.reject(new Error(`Expected a Turbo Stream response but got "${this.contentType}" instead`));
29349
+ }
29350
+ }
29351
+ async activeScript() {
29352
+ if (this.isScript) {
29353
+ const script = document.createElement("script");
29354
+ const metaTag = document.querySelector("meta[name=csp-nonce]");
29355
+ const nonce = metaTag && metaTag.content;
29356
+ if (nonce) {
29357
+ script.setAttribute("nonce", nonce);
29358
+ }
29359
+ script.innerHTML = await this.text;
29360
+ document.body.appendChild(script);
29361
+ } else {
29362
+ return Promise.reject(new Error(`Expected a Script response but got "${this.contentType}" instead`));
29363
+ }
29364
+ }
29365
+ };
29366
+
29367
+ // node_modules/@rails/request.js/src/request_interceptor.js
29368
+ var RequestInterceptor = class {
29369
+ static register(interceptor) {
29370
+ this.interceptor = interceptor;
29371
+ }
29372
+ static get() {
29373
+ return this.interceptor;
29374
+ }
29375
+ static reset() {
29376
+ this.interceptor = void 0;
29377
+ }
29378
+ };
29379
+
29380
+ // node_modules/@rails/request.js/src/lib/utils.js
29381
+ function getCookie(name) {
29382
+ const cookies = document.cookie ? document.cookie.split("; ") : [];
29383
+ const prefix = `${encodeURIComponent(name)}=`;
29384
+ const cookie = cookies.find((cookie2) => cookie2.startsWith(prefix));
29385
+ if (cookie) {
29386
+ const value = cookie.split("=").slice(1).join("=");
29387
+ if (value) {
29388
+ return decodeURIComponent(value);
29389
+ }
29390
+ }
29391
+ }
29392
+ function compact(object) {
29393
+ const result = {};
29394
+ for (const key in object) {
29395
+ const value = object[key];
29396
+ if (value !== void 0) {
29397
+ result[key] = value;
29398
+ }
29399
+ }
29400
+ return result;
29401
+ }
29402
+ function metaContent(name) {
29403
+ const element = document.head.querySelector(`meta[name="${name}"]`);
29404
+ return element && element.content;
29405
+ }
29406
+ function stringEntriesFromFormData(formData) {
29407
+ return [...formData].reduce((entries, [name, value]) => {
29408
+ return entries.concat(typeof value === "string" ? [[name, value]] : []);
29409
+ }, []);
29410
+ }
29411
+ function mergeEntries(searchParams, entries) {
29412
+ for (const [name, value] of entries) {
29413
+ if (value instanceof window.File) continue;
29414
+ if (searchParams.has(name) && !name.includes("[]")) {
29415
+ searchParams.delete(name);
29416
+ searchParams.set(name, value);
29417
+ } else {
29418
+ searchParams.append(name, value);
29419
+ }
29420
+ }
29421
+ }
29422
+
29423
+ // node_modules/@rails/request.js/src/fetch_request.js
29424
+ var FetchRequest = class {
29425
+ constructor(method, url, options = {}) {
29426
+ this.method = method;
29427
+ this.options = options;
29428
+ this.originalUrl = url.toString();
29429
+ }
29430
+ async perform() {
29431
+ try {
29432
+ const requestInterceptor = RequestInterceptor.get();
29433
+ if (requestInterceptor) {
29434
+ await requestInterceptor(this);
29435
+ }
29436
+ } catch (error) {
29437
+ console.error(error);
29438
+ }
29439
+ const fetch = this.responseKind === "turbo-stream" && window.Turbo ? window.Turbo.fetch : window.fetch;
29440
+ const response = new FetchResponse(await fetch(this.url, this.fetchOptions));
29441
+ if (response.unauthenticated && response.authenticationURL) {
29442
+ return Promise.reject(window.location.href = response.authenticationURL);
29443
+ }
29444
+ if (response.isScript) {
29445
+ await response.activeScript();
29446
+ }
29447
+ const responseStatusIsTurboStreamable = response.ok || response.unprocessableEntity;
29448
+ if (responseStatusIsTurboStreamable && response.isTurboStream) {
29449
+ await response.renderTurboStream();
29450
+ }
29451
+ return response;
29452
+ }
29453
+ addHeader(key, value) {
29454
+ const headers = this.additionalHeaders;
29455
+ headers[key] = value;
29456
+ this.options.headers = headers;
29457
+ }
29458
+ sameHostname() {
29459
+ if (!this.originalUrl.startsWith("http:")) {
29460
+ return true;
29461
+ }
29462
+ try {
29463
+ return new URL(this.originalUrl).hostname === window.location.hostname;
29464
+ } catch (_2) {
29465
+ return true;
29466
+ }
29467
+ }
29468
+ get fetchOptions() {
29469
+ return {
29470
+ method: this.method.toUpperCase(),
29471
+ headers: this.headers,
29472
+ body: this.formattedBody,
29473
+ signal: this.signal,
29474
+ credentials: this.credentials,
29475
+ redirect: this.redirect
29476
+ };
29477
+ }
29478
+ get headers() {
29479
+ const baseHeaders = {
29480
+ "X-Requested-With": "XMLHttpRequest",
29481
+ "Content-Type": this.contentType,
29482
+ Accept: this.accept
29483
+ };
29484
+ if (this.sameHostname()) {
29485
+ baseHeaders["X-CSRF-Token"] = this.csrfToken;
29486
+ }
29487
+ return compact(
29488
+ Object.assign(baseHeaders, this.additionalHeaders)
29489
+ );
29490
+ }
29491
+ get csrfToken() {
29492
+ return getCookie(metaContent("csrf-param")) || metaContent("csrf-token");
29493
+ }
29494
+ get contentType() {
29495
+ if (this.options.contentType) {
29496
+ return this.options.contentType;
29497
+ } else if (this.body == null || this.body instanceof window.FormData) {
29498
+ return void 0;
29499
+ } else if (this.body instanceof window.File) {
29500
+ return this.body.type;
29501
+ }
29502
+ return "application/json";
29503
+ }
29504
+ get accept() {
29505
+ switch (this.responseKind) {
29506
+ case "html":
29507
+ return "text/html, application/xhtml+xml";
29508
+ case "turbo-stream":
29509
+ return "text/vnd.turbo-stream.html, text/html, application/xhtml+xml";
29510
+ case "json":
29511
+ return "application/json, application/vnd.api+json";
29512
+ case "script":
29513
+ return "text/javascript, application/javascript";
29514
+ default:
29515
+ return "*/*";
29516
+ }
29517
+ }
29518
+ get body() {
29519
+ return this.options.body;
29520
+ }
29521
+ get query() {
29522
+ const originalQuery = (this.originalUrl.split("?")[1] || "").split("#")[0];
29523
+ const params = new URLSearchParams(originalQuery);
29524
+ let requestQuery = this.options.query;
29525
+ if (requestQuery instanceof window.FormData) {
29526
+ requestQuery = stringEntriesFromFormData(requestQuery);
29527
+ } else if (requestQuery instanceof window.URLSearchParams) {
29528
+ requestQuery = requestQuery.entries();
29529
+ } else {
29530
+ requestQuery = Object.entries(requestQuery || {});
29531
+ }
29532
+ mergeEntries(params, requestQuery);
29533
+ const query = params.toString();
29534
+ return query.length > 0 ? `?${query}` : "";
29535
+ }
29536
+ get url() {
29537
+ return this.originalUrl.split("?")[0].split("#")[0] + this.query;
29538
+ }
29539
+ get responseKind() {
29540
+ return this.options.responseKind || "html";
29541
+ }
29542
+ get signal() {
29543
+ return this.options.signal;
29544
+ }
29545
+ get redirect() {
29546
+ return this.options.redirect || "follow";
29547
+ }
29548
+ get credentials() {
29549
+ return this.options.credentials || "same-origin";
29550
+ }
29551
+ get additionalHeaders() {
29552
+ return this.options.headers || {};
29553
+ }
29554
+ get formattedBody() {
29555
+ const bodyIsAString = Object.prototype.toString.call(this.body) === "[object String]";
29556
+ const contentTypeIsJson = this.headers["Content-Type"] === "application/json";
29557
+ if (contentTypeIsJson && !bodyIsAString) {
29558
+ return JSON.stringify(this.body);
29559
+ }
29560
+ return this.body;
29561
+ }
29562
+ };
29563
+
29564
+ // node_modules/@rails/request.js/src/verbs.js
29565
+ async function post(url, options) {
29566
+ const request = new FetchRequest("post", url, options);
29567
+ return request.perform();
29568
+ }
29569
+
29289
29570
  // app/javascript/controllers/rhino_field_controller.js
29290
29571
  function rgbStyleToHex2(color) {
29291
29572
  if (!color || color.indexOf("rgb") < 0) {
@@ -29302,6 +29583,10 @@ img.ProseMirror-separator {
29302
29583
  }
29303
29584
  var rhino_field_controller_default = class extends Controller {
29304
29585
  static targets = ["textColorInput", "backgroundColorInput"];
29586
+ static values = {
29587
+ resourceName: String,
29588
+ resourceId: String
29589
+ };
29305
29590
  get editor() {
29306
29591
  return this.element.editor;
29307
29592
  }
@@ -29358,6 +29643,33 @@ img.ProseMirror-separator {
29358
29643
  this.textColorInputTarget.value = this.DEFAULT_TEXT_COLOR;
29359
29644
  }
29360
29645
  }
29646
+ async openGallery() {
29647
+ post(`${window.Avo.configuration.root_path}/media_library`, {
29648
+ query: {
29649
+ resource_name: this.resourceNameValue,
29650
+ record_id: this.resourceIdValue,
29651
+ controller_selector: this.element.dataset.rhinoFieldUniqueSelectorValue,
29652
+ controller_name: this.identifier
29653
+ },
29654
+ responseKind: "turbo-stream"
29655
+ });
29656
+ }
29657
+ // Invoked by the other controllers (media-library)
29658
+ insertAttachments(attachments, event) {
29659
+ console.log("insertAttachment<>", this, event);
29660
+ const editorAttachments = attachments.map((attachment) => {
29661
+ const { blob, path } = attachment;
29662
+ return new AttachmentManager({
29663
+ src: path,
29664
+ width: blob.width,
29665
+ height: blob.height,
29666
+ filename: blob.filename,
29667
+ contentType: blob.content_type,
29668
+ previewable: true
29669
+ });
29670
+ });
29671
+ this.editor?.chain().focus().setAttachment(editorAttachments).run();
29672
+ }
29361
29673
  setBackgroundColor(event) {
29362
29674
  const color = event.target.value;
29363
29675
  if (color) {