"use strict";(self.webpackChunknocobase=self.webpackChunknocobase||[]).push([[9042,113,7087],{67087:function(f,o,e){e.r(o),e.d(o,{FormJSFieldItemRunJSContext:function(){return t}});var _=e(72004),s=e.n(_),r=e(12444),a=e.n(r),l=e(31996),u=e.n(l),d=e(26037),i=e.n(d),m=e(67946),t=function(c){u()(n,c);var b=i()(n);function n(){return a()(this,n),b.apply(this,arguments)}return s()(n)}(m.Uo);t.define({label:"FormJSFieldItem RunJS context",properties:{element:`ElementProxy instance providing a safe DOM container for form field rendering.
      Supports innerHTML, append, and other DOM manipulation methods.`,value:"Current field value (read-only in display mode; in controlled scenarios, use setProps to modify).",record:`Current record data object (read-only).
      Contains all field values of the parent record.`,formValues:{description:"Snapshot of current form values (object). Available in form contexts (CreateForm/EditForm).",detail:"Record<string, any>",examples:["const { name, status } = ctx.formValues || {};"]}},methods:{onRefReady:`Wait for form field container DOM element to be ready before executing callback.
      Parameters: (ref: React.RefObject, callback: (element: HTMLElement) => void, timeout?: number) => void`,setProps:`Set form field properties programmatically.
      Parameters: (fieldModel: any, props: { value?: any, disabled?: boolean, visible?: boolean }) => void
      Example: ctx.setProps(fieldModel, { value: "new value" })`}}),t.define({label:"\u8868\u5355 JS \u5B57\u6BB5\u9879 RunJS \u4E0A\u4E0B\u6587",properties:{element:"ElementProxy\uFF0C\u8868\u5355\u5B57\u6BB5\u5BB9\u5668",value:"\u5B57\u6BB5\u503C\uFF08\u5C55\u793A\u6A21\u5F0F\u4E3A\u53EA\u8BFB\uFF1B\u53D7\u63A7\u573A\u666F\u7528 setProps \u4FEE\u6539\uFF09",record:"\u5F53\u524D\u8BB0\u5F55\uFF08\u53EA\u8BFB\uFF09",formValues:{description:"\u5F53\u524D\u8868\u5355\u503C\u5FEB\u7167\uFF08\u5BF9\u8C61\uFF09\u3002\u4EC5\u8868\u5355\u76F8\u5173\u4E0A\u4E0B\u6587\u53EF\u7528\uFF08Create/Edit Form\uFF09\u3002",detail:"Record<string, any>",examples:["const { name, status } = ctx.formValues || {};"]}},methods:{onRefReady:"\u5BB9\u5668\u5C31\u7EEA\u56DE\u8C03",setProps:"\u8BBE\u7F6E\u8868\u5355\u9879\u5C5E\u6027\uFF1A`setProps(fieldModel, { value })`\uFF08\u7531\u8054\u52A8/\u8868\u5355\u4E0A\u4E0B\u6587\u63D0\u4F9B\uFF09"}},{locale:"zh-CN"})},40113:function(f,o,e){e.r(o),e.d(o,{JSFieldRunJSContext:function(){return t}});var _=e(72004),s=e.n(_),r=e(12444),a=e.n(r),l=e(31996),u=e.n(l),d=e(26037),i=e.n(d),m=e(67946),t=function(c){u()(n,c);var b=i()(n);function n(){return a()(this,n),b.apply(this,arguments)}return s()(n)}(m.Uo);t.define({label:"JSField RunJS context",properties:{element:`ElementProxy instance providing a safe DOM container for field rendering.
      Supports innerHTML, append, and other DOM manipulation methods.`,value:`Current value of the field (read-only).
      Contains the data value stored in this field.`,record:`Current record data object (read-only).
      Contains all field values of the parent record.`,collection:`Collection definition metadata (read-only).
      Provides schema information about the collection this field belongs to.`},methods:{onRefReady:`Wait for field container DOM element to be ready before executing callback.
      Parameters: (ref: React.RefObject, callback: (element: HTMLElement) => void, timeout?: number) => void
      Example: ctx.onRefReady(ctx.ref, (el) => { el.innerHTML = ctx.value })`}}),t.define({label:"JS \u5B57\u6BB5 RunJS \u4E0A\u4E0B\u6587",properties:{element:"ElementProxy\uFF0C\u5B57\u6BB5\u6E32\u67D3\u5BB9\u5668\uFF0C\u652F\u6301 innerHTML/append \u7B49 DOM \u64CD\u4F5C",value:"\u5B57\u6BB5\u5F53\u524D\u503C\uFF08\u53EA\u8BFB\uFF09",record:"\u5F53\u524D\u8BB0\u5F55\u5BF9\u8C61\uFF08\u53EA\u8BFB\uFF0C\u5305\u542B\u7236\u8BB0\u5F55\u5168\u90E8\u5B57\u6BB5\u503C\uFF09",collection:"\u96C6\u5408\u5B9A\u4E49\u5143\u6570\u636E\uFF08\u53EA\u8BFB\uFF0C\u63CF\u8FF0\u5B57\u6BB5\u6240\u5C5E\u96C6\u5408\u7684 Schema\uFF09"},methods:{onRefReady:"\u5728\u5B57\u6BB5\u5BB9\u5668 DOM \u5C31\u7EEA\u540E\u6267\u884C\u56DE\u8C03\u3002\u53C2\u6570\uFF1A(ref, callback, timeout?)\uFF1B\u793A\u4F8B\uFF1Actx.onRefReady(ctx.ref, el => { el.innerHTML = ctx.value })"}},{locale:"zh-CN"})},19042:function(f,o,e){e.r(o);var _=e(40113),s=e(67087),r={contexts:[_.JSFieldRunJSContext,s.FormJSFieldItemRunJSContext],prefix:"sn-jsf-relative-time",label:"Display date field as relative time",description:"Render date values as \u201C3 days ago\u201D, \u201Cjust now\u201D, etc.",locales:{"zh-CN":{label:"\u5C06\u65E5\u671F\u5B57\u6BB5\u663E\u793A\u4E3A\u76F8\u5BF9\u65F6\u95F4",description:"\u5C06\u65E5\u671F\u663E\u793A\u4E3A\u201C3\u5929\u524D\u201D\u3001\u201C\u521A\u521A\u201D\u7B49\u76F8\u5BF9\u65F6\u95F4"}},content:`
const formatRelativeTime = (date) => {
  const now = new Date();
  const diff = now - new Date(date);
  const seconds = Math.floor(diff / 1000);
  const minutes = Math.floor(seconds / 60);
  const hours = Math.floor(minutes / 60);
  const days = Math.floor(hours / 24);
  const months = Math.floor(days / 30);
  const years = Math.floor(days / 365);

  if (seconds < 60) return ctx.t('just now');
  if (minutes < 60) return ctx.t('{{count}} minutes ago', { count: minutes });
  if (hours < 24) return ctx.t('{{count}} hours ago', { count: hours });
  if (days < 30) return ctx.t('{{count}} days ago', { count: days });
  if (months < 12) return ctx.t('{{count}} months ago', { count: months });
  return ctx.t('{{count}} years ago', { count: years });
};

const dateStr = ctx.value;
if (!dateStr) {
  ctx.render('-');
  return;
}

const relativeTime = formatRelativeTime(dateStr);
const fullDate = new Date(dateStr).toLocaleString();

ctx.render(\`
  <span title="\${fullDate}" style="cursor: help; color: #666;">
    \${relativeTime}
  </span>
\`);
`};o.default=r}}]);
