All files / app/mods root.ts

100% Statements 19/19
100% Branches 0/0
100% Functions 0/0
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455117x   117x     117x   117x 117x   117x     117x   117x   117x                                                 117x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         117x                                     117x                             117x                                                   117x                                           117x                                               117x                       117x                                         117x                       117x                                
import { DateTime } from 'luxon';
// @ts-ignore
import extModelText from '../model/ext.ts' with { loader: 'text' };
import { Plugin } from '../model/plugin';
// @ts-ignore
import pluginModelText from '../model/plugin.ts' with { loader: 'text' };
// @ts-ignore
import refModelText from '../model/ref.ts' with { loader: 'text' };
import { Mod, modSchema } from '../model/tag';
// @ts-ignore
import tagModelText from '../model/tag.ts' with { loader: 'text' };
import { Template } from '../model/template';
// @ts-ignore
import templateModelText from '../model/template.ts' with { loader: 'text' };
// @ts-ignore
import userModelText from '../model/user.ts' with { loader: 'text' };
 
export const rootPlugin: Plugin = {
  tag: 'plugin',
  name: $localize`๐Ÿ“ฆ๏ธ Root Plugin`,
  config: {
    mod: $localize`โš“๏ธ Root`,
    version: 1,
    default: true,
    view: $localize`๐Ÿ“ฆ๏ธ`,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    description: $localize`Add Ref sorts.`,
    sorts: [
      { sort: 'created', label: $localize`โœจ๏ธ new` },
      { sort: 'published', label: $localize`๐Ÿ“…๏ธ published` },
      { sort: 'modified', label: $localize`๐Ÿ•“๏ธ modified` },
      { sort: 'metadata->modified', label: $localize`๐Ÿงต๏ธ new response`, title: $localize`Date of new response` },
      { sort: 'title', label: $localize`๐Ÿ‡ฆ๏ธ title` },
      { sort: 'url', label: $localize`๐Ÿ”—๏ธ url` },
      { sort: 'scheme', label: $localize`๐Ÿณ๏ธ๏ธ scheme` },
      { sort: 'tags:len', label: $localize`๐Ÿท๏ธ tags`, title: $localize`Number of tags` },
      { sort: 'metadata->responses', label: $localize`๐Ÿ’Œ๏ธ responses`, title: $localize`Number of responses` },
      { sort: 'sources:len', label: $localize`๐Ÿ“œ๏ธ sources`, title: $localize`Number of sources` },
    ],
  }
};
 
export const rootTemplate: Template = {
  tag: '',
  name: $localize`โš“๏ธ Root Template`,
  config: {
    mod: $localize`โš“๏ธ Root`,
    version: 1,
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    description: $localize`Add common features Ext tag pages: Adding pinned Refs, sidebar markdown,
    a custom theme and a set of non-global custom themes to choose from in addition to global themes.`,
    aiInstructions: ` # Root Template
    The root template uses the empty string as a tag. Since templates are matched to Exts by prefix matching,
    the root template matches every tag. Here are the models in use:
    \`\`\`typescript
    ` + tagModelText + `
    ` + refModelText + `
    ` + extModelText + `
    ` + userModelText + `
    ` + pluginModelText + `
    ` + templateModelText + `
    \`\`\`
 
    The root template sets up basic functionality such as deleted icons and filters, and basic Ext config:
    \`\`\`typescript
    export interface RootConfig {
      pinned?: string[];
      sidebar?: string;
      modmail?: boolean;
      dms?: string;
      queryFilters?: { query: string, label?: string}[];
      responseFilters?: { response: \`plugin/\${string}\` | \`!plugin/\${string}\`, label?: string }[];
      themes?: Record<string, string>;
      theme?: string;
      defaultSort?: string;
      submitText?: boolean;
      addTags?: string[];
      defaultExpanded?: boolean;
      hideEdit?: boolean;
      disableResize?: boolean;
      defaultCols?: number;
    }
    \`\`\`
    `,
    icons: [
      { tag: 'plugin/delete', label: $localize`๐Ÿ—‘๏ธ`, global: true },
    ],
    filters: [
      { scheme: 'http:', label: $localize`http:`, group: $localize`Schemes ๐Ÿณ๏ธ๏ธ`},
      { scheme: 'https:', label: $localize`https:`, group: $localize`Schemes ๐Ÿณ๏ธ๏ธ`},
      { scheme: 'ftp:', label: $localize`ftp:`, group: $localize`Schemes ๐Ÿณ๏ธ๏ธ`},
      { scheme: 'email:', label: $localize`email:`, group: $localize`Schemes ๐Ÿณ๏ธ๏ธ`},
      { scheme: 'tel:', label: $localize`tel:`, group: $localize`Schemes ๐Ÿณ๏ธ๏ธ`},
      { scheme: 'magnet:', label: $localize`magnet:`, group: $localize`Schemes ๐Ÿณ๏ธ๏ธ`},
    ],
    sorts: [
      { sort: 'modified', label: $localize`๐Ÿ•“๏ธ modified` },
      { sort: 'name', label: $localize`๐Ÿ‡ฆ๏ธ name` },
      { sort: 'tag', label: $localize`๐Ÿท๏ธ tag` },
      { sort: 'tag:len', label: $localize`/๐Ÿท๏ธ level`, title: $localize`Number of subtags` },
      { sort: 'origin', label: $localize`๐Ÿ›๏ธ origin` },
      { sort: 'origin:len', label: $localize`๐Ÿช† nesting` },
    ],
    form: [{
      key: 'pinned',
      type: 'refs',
      props: {
        label: $localize`Pinned:`,
        addText: $localize`+ Add another pinned link`,
      },
      fieldArray: {
        props: {
          label: $localize`๐Ÿ“Œ๏ธ`,
        }
      },
    }, {
      key: 'submitText',
      type: 'select',
      defaultValue: false,
      props: {
        label: $localize`Submit:`,
        options: [
          { value: true, label: $localize`Text Posts` },
          { value: false, label: $localize`Link Posts` },
        ],
      }
    }, {
      key: 'addTags',
      type: 'tags',
      defaultValue: ['public'],
      props: {
        label: $localize`Add Tags:`
      },
    }, {
      key: 'queryFilters',
      type: 'list',
      props: {
        label: $localize`Query Filters:`,
        addText: $localize`+ Add another query filter`,
      },
      fieldArray: {
        fieldGroup: [{
          key: 'label',
          type: 'string',
          props: {
            label: $localize`Label:`
          }
        }, {
          key: 'query',
          type: 'query',
          props: {
            required: true,
          }
        }]
      }
    }],
    advancedForm: [{
      key: 'dms',
      type: 'tag',
      props: {
        label: $localize`DMs:`
      }
    }, {
      key: 'responseFilters',
      type: 'list',
      props: {
        label: $localize`Response Filters:`,
        addText: $localize`+ Add another response filter`,
      },
      fieldArray: {
        fieldGroup: [{
          key: 'label',
          type: 'string',
          props: {
            label: $localize`Label:`
          }
        }, {
          key: 'response',
          type: 'plugin',
          props: {
            required: true,
          }
        }]
      }
    }, {
      key: 'defaultCols',
      type: 'select',
      props: {
        label: $localize`Columns:`,
        options: [
          { label: $localize`Default` },
          { value: 1, label: $localize`1 Column` },
          { value: 2, label: $localize`2 Columns` },
          { value: 3, label: $localize`3 Columns` },
          { value: 4, label: $localize`4 Columns` },
          { value: 5, label: $localize`5 Columns` },
          { value: 6, label: $localize`6 Columns` },
        ],
      },
    }, {
      key: 'childTags',
      type: 'number',
      props: {
        label: $localize`Child Tags in Sidebar:`,
      },
    }, {
      key: 'noFloatingSidebar',
      type: 'boolean',
      props: {
        label: $localize`No Floating Sidebar:`,
      },
    }, {
      key: 'defaults',
      type: 'boolean',
      props: {
        label: $localize`Defaults:`,
      },
    }],
  },
  defaults: <RootConfig> {
    defaultSort: ['published'],
    addTags: ['public'],
  },
  schema: {
    optionalProperties: {
      pinned: { elements: { type: 'string' } },
      sidebar: { type: 'string' },
      popover: { type: 'string' },
      modmail: { type: 'boolean' },
      dms: { type: 'string' },
      queryFilters: { elements: {
        properties: {
          query: { type: 'string' },
        },
        optionalProperties: {
          label: { type: 'string' },
        }
      }},
      responseFilters: { elements: {
        properties: {
          response: { type: 'string' },
        },
        optionalProperties: {
          label: { type: 'string' },
        }
      }},
      themes: { values: { type: 'string' } },
      theme: { type: 'string' },
      defaultSort: { elements: { type: 'string' } },
      defaultFilter: { elements: { type: 'string' } },
      submitText: { type: 'boolean'},
      addTags: { elements: { type: 'string' } },
      defaultExpanded: { type: 'boolean'},
      hideEdit: { type: 'boolean'},
      disableResize: { type: 'boolean'},
      defaultCols: { type: 'int8'},
      childTags: { type: 'int8'},
      noFloatingSidebar: { type: 'boolean'},
      defaults: { type: 'boolean'},
    },
  },
};
 
export interface RootConfig {
  pinned?: string[];
  sidebar?: string;
  popover?: string;
  modmail?: boolean;
  dms?: string;
  queryFilters?: { query: string, label?: string}[];
  responseFilters?: { response: `plugin/${string}` | `+plugin/${string}` | `_plugin/${string}` | `!plugin/${string}` | `!+plugin/${string}` | `!_plugin/${string}`, label?: string }[];
  themes?: Record<string, string>;
  theme?: string;
  defaultSort?: string[];
  defaultFilter?: string[];
  submitText?: boolean;
  addTags?: string[];
  defaultExpanded?: boolean;
  hideEdit?: boolean;
  disableResize?: boolean;
  defaultCols?: number;
  childTags?: number;
  noFloatingSidebar?: boolean;
  defaults?: boolean;
}
 
export const internalTemplate: Template = {
  tag: 'internal',
  name: $localize`โš™๏ธ Internal`,
  config: {
    mod: $localize`โš“๏ธ Root`,
    version: 1,
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    description: $localize`Internal Refs which should be hidden by default`,
    icons: [
      { thumbnail: $localize`โš™๏ธ`, order: -20 },
    ],
    filters: [
      { query: 'internal', label: $localize`โš™๏ธ internal`, title: $localize`Show hidden comments and reactions`, group: $localize`Filters ๐Ÿ•ต๏ธ๏ธ` },
      { scheme: 'internal:', label: $localize`internal:`, group: $localize`Schemes ๐Ÿณ๏ธ๏ธ`},
    ],
  },
};
 
export const altPlugin: Plugin = {
  tag: 'plugin/alt',
  name: $localize`โ„น๏ธ Alt Text`,
  config: {
    mod: $localize`โš“๏ธ Root`,
    version: 1,
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    description: $localize`Use comment as alt text`,
    icons: [
      { tag: 'plugin/alt', label: $localize`โ„น๏ธ`, global: true, order: -3 },
    ],
  },
};
 
export const lockedTemplate: Template = {
  tag: 'locked',
  name: $localize`๐Ÿ”’๏ธ Locked`,
  config: {
    mod: $localize`โš“๏ธ Root`,
    version: 1,
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    description: $localize`Show locked icon on locked Refs and add filters for
      locked and unlocked Refs`,
    icons: [
      { label: $localize`๐Ÿ”’๏ธ`, title: $localize`Locked`, order: -2 },
    ],
    actions: [
      { tag: '_plugin/delta/unlock', labelOff: $localize`unlock`, title: $localize`Unlock this post to allow editing`},
    ],
    filters: [
      { query: 'locked', label: $localize`๐Ÿ”’๏ธ locked`, title: $localize`Locked`, group: $localize`Filters ๐Ÿ•ต๏ธ๏ธ` },
      { query: '!locked', label: $localize`๐Ÿ”“๏ธ unlocked`, title: $localize`Unlocked`, group: $localize`Filters ๐Ÿ•ต๏ธ๏ธ` },
    ],
    editorButtons: [
      { labelOff: $localize`๐Ÿ”“๏ธ`, labelOn: $localize`๐Ÿ”’๏ธ`, title: $localize`Lock this post to prevent editing`, ribbon: true, order: 100, global: true },
    ],
  },
};
 
export const unlockPlugin: Plugin = {
  tag: '_plugin/delta/unlock',
  name: $localize`๐Ÿ”“๏ธ Unlock`,
  config: {
    mod: $localize`โš“๏ธ Root`,
    version: 1,
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    timeoutMs: 30_000,
    language: 'javascript',
    // language=JavaScript
    script: `
      const ref = JSON.parse(require('fs').readFileSync(0, 'utf-8'));
      if (ref?.tags?.find(t => t === 'locked' || t?.startsWith('locked/'))) {
        ref.tags = ref.tags.filter(t => t !== 'locked' && !t.startsWith('locked/'));
        delete ref.metadata;
        console.log(JSON.stringify({ ref: [ref] }))
      }
    `,
  },
};
 
export const privateTemplate: Template = {
  tag: 'public',
  name: $localize`๐ŸŒ๏ธ Public`,
  config: {
    mod: $localize`โš“๏ธ Root`,
    version: 1,
    default: true,
    reply: ['public'],
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    description: $localize`Show private icon on non-public Refs and add filters for
      private and public Refs`,
    icons: [
      { label: $localize`๐Ÿ‘๏ธ`, tag: '!public', title: $localize`Private`, order: -2, global: true },
    ],
    filters: [
      { query: 'public', label: $localize`๐ŸŒ๏ธ public`, title: $localize`Public read access`, group: $localize`Filters ๐Ÿ•ต๏ธ๏ธ` },
      { query: '!public', label: $localize`๐Ÿ‘๏ธ private`, title: $localize`Private read access`, group: $localize`Filters ๐Ÿ•ต๏ธ๏ธ` },
    ],
    editorButtons: [
      { labelOff: $localize`๐Ÿ‘๏ธ`, labelOn: $localize`๐ŸŒ๏ธ`, title: $localize`Toggle ๐ŸŒ๏ธ Public or ๐Ÿ‘๏ธ Private`, remember: true, order: -1, global: true },
    ],
  },
};
 
export const diffTemplate: Template = {
  tag: 'config/diff',
  name: $localize`๐Ÿ”€ Diff`,
  config: {
    mod: $localize`โš“๏ธ Root`,
    version: 1,
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    description: $localize`Enable diff action for comparing reference versions using Monaco editor`,
  },
};
 
export const modPlugin: Plugin = {
  tag: 'plugin/mod',
  name: $localize`๐ŸŽ๏ธ Mod`,
  config: {
    mod: $localize`โš“๏ธ Root`,
    version: 2,
    default: true,
    embeddable: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    description: $localize`A mod which can be installed by an admin.`,
    aiInstructions: `# plugin/mod
    The plugin/mod plugin holds mods in a Ref to be installed by an admin.`,
    icons: [{ label: $localize`๐ŸŽ๏ธ`, order: 2 }],
    filters: [
      { query: 'plugin/mod', label: $localize`๐ŸŽ๏ธ mod`, title: $localize`Mod`, group: $localize`Plugins ๐Ÿงฐ๏ธ` },
    ],
    actions: [{ event: 'install', label: $localize`install`, title: $localize`Install this mod`, role: 'ROLE_ADMIN', confirm: $localize`Are you sure you want to install this mod?` }],
  },
  schema: modSchema,
};
 
export const modReceiptPlugin: Plugin = {
  tag: 'plugin/mod/receipt',
  name: $localize`๐ŸŽ๏ธ Mod Receipt`,
  config: {
    mod: $localize`โš“๏ธ Root`,
    version: 1,
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    description: $localize`Log of installed mod before any customization. Used for 3 way merges.`,
  },
};
 
export const rootMod: Mod = {
  plugin: [
    rootPlugin,
    altPlugin,
    unlockPlugin,
    modPlugin,
    modReceiptPlugin
  ],
  template: [
    rootTemplate,
    internalTemplate,
    lockedTemplate,
    privateTemplate,
    diffTemplate,
  ]
};